3

I am using WCF service. The problem I have is its starts using double memory.

I am using HTTPS binding

<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"> 

Here is the code I am using to upload

using (Stream fileStream = File.OpenRead(logsZipFullPath))
{
  // Call web server
  UploadFileResponse response = _webServiceHelper.UploadFile(fileStream, currentDate, ".zip", string.Empty);
  fileStream.Close();
}

Here is my model

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

    }

My zip file is of 80MB.

The problem I have is at the start of the service its using 26mb which is quite fine. At the first call it uses 136MB after call completes it goes down to 26mb. which is also fine. after the second call to upload it starts using 346MB which again gets down to 26mb after service call. My question is why it is using 346MB when the file is of only 80MB? My GC and disponse has been called correctly. But, is this normal behaviour or I am missing anything?

Just code
  • 13,553
  • 10
  • 51
  • 93

1 Answers1

1

finally found a work around for this. According to this post

wsHttpBinding is the full-blown binding, which supports a ton of WS-* features and standards - it has lots more security features, you can use sessionful connections, you can use reliable messaging, you can use transactional control - just a lot more stuff, but wsHttpBinding is also a lot *heavier" and adds a lot of overhead to your messages as they travel across the network

I think this is the main reason why the memory usage is high. Our requirement was to use the HTTPS certificate and we are able to use this with basicHttpBinding. SO, I changed my settings like this

<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>

Note: I changed security mode none to transport to support https.

Now, everything works without the issue. Two possible things which causes memory issues.

  1. wsHttpBinding overheads
  2. Stream mode is not supported in wsHttpBinding
Just code
  • 13,553
  • 10
  • 51
  • 93