wcf返回类时出错

wcf返回类时出错,wcf,class,config,Wcf,Class,Config,我已经为这个错误挣扎了一段时间: 接收对的HTTP响应时出错 …8332/Service1.svc。这可能是由于服务端点造成的 绑定不使用HTTP协议。这也可能是由于HTTP 服务器正在中止请求上下文(可能是由于 服务关闭)。有关详细信息,请参阅服务器日志 我跟踪了错误,很明显这与绑定或连接有关,我不知道如何解决。 …我把课程和配置文件放在下面。请指导我。提前谢谢 [DataContract] public class filepack { string

我已经为这个错误挣扎了一段时间:

接收对的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>
[DataContract]
公共类文件包
{
字符串filesize=“0”;
int accesspermitid=0;
System.IO.Stream str;
[数据成员]
public System.IO.Stream Filestr
{
获取{return str;}
设置{str=value;}
}
[数据成员]
公共字符串文件大小
{
获取{return filesize;}
设置{filesize=value;}
}
[数据成员]
公共int访问权限
{
获取{return accesspermitid;}
设置{accesspermitid=value;}
}
}

您不能发送流。您需要在发送之前将流读到底,从而将流具体化为真正的数据对象(例如字符串或字节数组),或者如果您真的想要流(我怀疑这一点),您可以读取。

从类中删除流并单独返回流,似乎可以解决此问题!
但我不知道这对解决它有什么帮助

我相信问题是由于水流造成的。。您在编程中使用的派生流是什么。我想建议您使用实际的流类型并进行测试下面的另一个答案对我的案例提出了相同的建议,但正如我对他的评论一样,我需要在运行时停用我在服务器上公开的其他方法的流媒体功能。我怎么做?事实上,我正在通过此流传输文件。因此,这可能是我应该使用的东西。但问题是,文件传输只是我应用程序的功能之一,即其他方法不需要流媒体,所以我不应该对他们使用它。所以问题是我如何在运行时通过代码激活/停用流媒体?