WCF Service Message Timeouts, Size Limits, Tips and Tricks

Is your WFC Service hitting the Maximum Limits set on the default service configurations? Open up the artificial constraints of the WCF Service Debugging WCF Services and message sizes. Caveat emptor: If you need to increase the size of the of the contracts, it probably indicates that you should reexamine the design of your data contract.  In any case, to “Open Up” the service, you will need to set on both the client and server side configurations:

1.        Timeouts

2.       Message Sizes

3.       Max Objects In Graph

Service side configurations

<system.serviceModel>

    <behaviors>

      <serviceBehaviors>

        <behaviorname**=****"Server.WcfService.MyServiceBehavior">**

          <serviceMetadata httpGetEnabled=****"true" httpsGetEnabled="false" />

          <serviceDebug includeExceptionDetailInFaults=****"true" />

          <dataContractSerializer maxItemsInObjectGraph=****"2147483647" />

        </behavior>

      </serviceBehaviors>

    </behaviors>

    <services>

      <service behaviorConfiguration="Server.WcfService.MyServiceBehavior"       name="Server.WcfService.MyService">

<endpoint address="http://MyServer:1260/MyService.svc" binding="wsHttpBinding"

bindingConfiguration="MyServiceBinding" contract="Server.WcfService.IMyService" />

        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

      </service>

    </services>

    <bindings>

      <wsHttpBinding>

        <binding name=****"MyServiceBinding"

                 maxReceivedMessageSize**=****"2147483647"**

                 openTimeout**=****"00:10:00"**

                 receiveTimeout**=****"00:10:00"**

                 sendTimeout**=****"00:10:00"**

                 closeTimeout**=****"00:10:00"**

                 maxBufferPoolSize**=****"2147483647" >**

        </binding>

      </wsHttpBinding>

    </bindings>

 </system.serviceModel>

Client side configurations

<system.serviceModel>

    <bindings>

      <wsHttpBinding>

<binding name="WSHttpBinding_IMyService" closeTimeout**="00:10:00"** openTimeout**="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647**" maxReceivedMessageSize**=****"2147483647**" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">

      <readerQuotas maxDepth="32"

maxStringContentLength**=****"2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647"**

maxNameTableCharCount**=****"2147483647"** />

<reliableSessionordered="true" inactivityTimeout**=****"00:10:00"** enabled="false"/>

        </binding>

      </wsHttpBinding>

    </bindings>

    <client>

<endpoint address= binding="wsHttpBinding"

bindingConfiguration="WSHttpBinding_IMyService" contract="MyServiceReference.IMyService" name="WSHttpBinding_IMyService"

      behaviorConfiguration**=****"MyServiceBehavior**"/>

    </client>

    <behaviors>

      <endpointBehaviors>

        <behavior name=****"MyServiceBehavior">

<dataContractSerializermaxItemsInObjectGraph**=****"2147483647" />**

        </behavior>

      </endpointBehaviors>

    </behaviors>

 </system.serviceModel>

What is this 2,147,483,647business? It is equal to 231 – 1, the max value of a 32 bit signed integer. 

When setting these tags, you should save yourself some headaches and use the Configuration Editor (SvcConfigEditor.exe): http://msdn.microsoft.com/en-us/library/ms732009.aspx

To test out your developed client, you can call the WCF service directly without writing your own client. Microsoft has provided one: http://msdn.microsoft.com/en-us/library/bb552364.aspx

Security: use it. Make sure your client and service side tags match. You may have noticed that it is absent from the above example.  That means that it is going to use the default which is Message for this particular binding type. http://msdn.microsoft.com/en-us/library/ms731059.aspx

When the errors you are receiving don’t seem to make any sense, you can add robust diagnostics by adding the following tag (make sure the service has write access to the location specified in the InitializeData):

 <system.diagnostics>

    <trace autoflush="true" />

    <sources>

      <source name="System.ServiceModel"

              switchValue="Information, ActivityTracing"

              propagateActivity="true">

        <listeners>

          <add name="sdt"

              type="System.Diagnostics.XmlWriterTraceListener"

              initializeData= "serviceLog.svcLog" />

        </listeners>

      </source>

    </sources>

 </system.diagnostics>

Call the WCF Service and then view the output file with the SVC Trace viewer tool: http://msdn.microsoft.com/en-us/library/ms732023.aspx

This article is part of the GWB Archives. Original Author: smyers

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.