C# WCF内存急剧增加

C# WCF内存急剧增加,c#,wcf,file-upload,binding,stream,C#,Wcf,File Upload,Binding,Stream,我正在使用WCF服务。我的问题是它开始使用双内存 我使用的是HTTPS绑定 <wsHttpBinding> <binding name="secureHttpBinding" closeTimeout="04:01:00" openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00" allowCookies="false" bypassProxy

我正在使用WCF服务。我的问题是它开始使用双内存

我使用的是HTTPS绑定

<wsHttpBinding>
        <binding name="secureHttpBinding" closeTimeout="04:01:00" openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00" allowCookies="false"
                 bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                  messageEncoding="Text" textEncoding="utf-8"  useDefaultWebProxy="true">
          <readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/> 
          <security mode="Transport" >
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </wsHttpBinding>

 <endpoint address="https://localhost/test.svc"
                 binding="wsHttpBinding"
                 bindingConfiguration="secureHttpBinding"
                 contract="IWcfContract"
                 name="SecureBasicHttpBinding_WcfContract"> 
这是我的模型

[MessageContract]
    public class UploadFileRequest : IDisposable
    {
        [MessageBodyMember(Order = 1)]
        public Stream FileByteStream;
        [MessageHeader(MustUnderstand = true)]
        public string FileDescription;

    }
我的zip文件是80MB

我遇到的问题是,在服务开始时,它使用了26mb,这很好。在第一次调用时,它使用136MB,调用完成后,它将下降到26mb。这也很好。在第二次调用上载后,它开始使用346MB
在服务呼叫之后,它再次下降到26mb。我的问题是,当文件只有80MB时,为什么要使用346MB?我的GC和disponse已正确调用。但是,这是正常的行为还是我遗漏了什么

终于找到了解决方法。据

wsHttpBinding是成熟的绑定,它支持大量的WS-* 功能和标准-它有更多的安全功能,你可以 使用会话连接,您可以使用可靠的消息传递,您可以 使用事务控制-只是更多的东西,但是wsHttpBinding 也会更重,并且会给你的信息增加很多开销 他们通过网络旅行

我认为这是内存使用率高的主要原因。我们的要求是使用HTTPS证书,我们可以将其与basicHttpBinding一起使用。因此,我像这样更改了设置

<basicHttpBinding>
        <binding name="BasicHttpBinding_WcfContract" closeTimeout="04:01:00" openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00" allowCookies="false"
                 bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
                 maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed" useDefaultWebProxy="true">
          <readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
          <security mode="Transport"> <-- this is the main change
            <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
            <message clientCredentialType="UserName" algorithmSuite="Default"/>
          </security>
        </binding>
      </basicHttpBinding>

<basicHttpBinding>
        <binding name="BasicHttpBinding_WcfContract" closeTimeout="04:01:00" openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00" allowCookies="false"
                 bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
                 maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed" useDefaultWebProxy="true">
          <readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
          <security mode="Transport"> <-- this is the main change
            <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
            <message clientCredentialType="UserName" algorithmSuite="Default"/>
          </security>
        </binding>
      </basicHttpBinding>