通过wcf返回类时出错

时间:2013-03-19 15:01:42

标签: wcf class config

我一直在努力解决这个错误:

  

接收HTTP响应时发生错误   .... 8332 / Service1.svc。这可能是由于服务端点   绑定不使用HTTP协议。这也可能是由于HTTP造成的   请求上下文被服务器中止(可能是由于   服务关闭)。有关详细信息,请参阅服务器日志。

我追踪了错误,显然它与绑定或连接有关,我无法弄清楚如何解决。  ..我正在把课程和配置文件放在下面。请提前指导我。谢谢。

    [DataContract]
    public class filepack
    {
        string  filesize = "0";
        int  accesspermitid =0;
         System.IO.Stream str ;


         [DataMember]
         public System.IO.Stream Filestr
         {
             get { return str; }
             set { str = value; }
         }

        [DataMember]
        public string Filesize
        {
            get { return filesize; }
            set { filesize = value; }
        }

        [DataMember]
        public int Accesspermitid
        {
            get { return accesspermitid; }
            set { accesspermitid = value; }
        }


    }

  <configuration>
        <startup> 
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />

        </startup>

        <system.serviceModel>

            <behaviors>
                <endpointBehaviors>

                    <behavior name="debugbeh">
                        <dataContractSerializer />
                    </behavior>
                </endpointBehaviors>
            </behaviors>
            <bindings>
                <basicHttpBinding>
                    <binding name="BasicHttpBinding_IService1" maxBufferSize="500000000"
                        maxReceivedMessageSize="500000000">
                        <security mode="None">
                            <message algorithmSuite="Default" />
                        </security>
                    </binding>
                </basicHttpBinding>
            </bindings>
            <client>
                <endpoint address="http://localhost:8332/Service1.svc" behaviorConfiguration="debugbeh"
                    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
                    contract="vcpservice.IService1" name="BasicHttpBinding_IService1" />
            </client>

        </system.serviceModel>
    </configuration>







    <?xml version="1.0"?>
    <configuration>

      <system.diagnostics>
        <trace autoflush="true" />
        <sources>
          <source name="System.ServiceModel"
                  switchValue="Information, ActivityTracing"
                  propagateActivity="true">
            <listeners>
              <add name="sdt"
                  type="System.Diagnostics.XmlWriterTraceListener"
                  initializeData="c:\\logclientHOST.svclog"  />
            </listeners>
          </source>
        </sources>
      </system.diagnostics>

      <appSettings>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
      </appSettings>
      <system.web>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5"/>
      </system.web>
      <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding name="mybinding" closeTimeout="00:10:00" maxBufferPoolSize="52428800"
              maxBufferSize="500000000" maxReceivedMessageSize="500000000" />
          </basicHttpBinding>
        </bindings>
        <diagnostics>
          <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
        </diagnostics>
        <behaviors>
          <endpointBehaviors>
            <behavior name="NewBehavior0">
              <dataContractSerializer />
            </behavior>
          </endpointBehaviors>
          <serviceBehaviors>
            <behavior name="">
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"
                httpGetBinding="webHttpBinding" httpGetBindingConfiguration="" />
              <serviceDebug includeExceptionDetailInFaults="true" />
              <dataContractSerializer maxItemsInObjectGraph="2147483646" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <protocolMapping>
            <add binding="basicHttpsBinding" scheme="https" />
        </protocolMapping>    
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
        <!--
            To browse web app root directory during debugging, set the value below to true.
            Set to false before deployment to avoid disclosing web app folder information.
          -->
        <directoryBrowse enabled="true"/>
      </system.webServer>

    </configuration>

2 个答案:

答案 0 :(得分:1)

您无法发送信息流。您需要通过在发送之前将其读取到结尾来实现您的流到实际数据对象(例如字符串或字节数组),或者如果您真的想要流式传输(我怀疑)您可以阅读this。 / p>

答案 1 :(得分:0)

问题似乎是通过从类中删除流并单独返回来解决的! 但我不知道它是如何帮助解决它的!