Geeks With Blogs

Tim Murphy

Tim is a Solutions Architect for PSC Group, LLC. He has been an IT consultant since 1999 specializing in Microsoft technologies. Along with running the Chicago Information Technology Architects Group and speaking on Microsoft and architecture topics he was also contributing author on "The Definitive Guide to the Microsoft Enterprise Library".

I review for the O'Reilly Blogger Review Program

Technorati Profile

Tim Murphy's .NET Software Architecture Blog Adventures in Architecting and Developing .NET

Windows Communication Foundation is a powerful tool for building contract based messaging.  As with most powerful technologies with flexibility comes a fair amount of complexity.  I ran into one of these situation while trying to send files as part of message in the form of a byte array.

In itself this is a simple concept.  The problem is that the default configuration of WCF is setup to protect us from denial of service attacks to the best of its ability.  In order to achieve this it is setup for relatively small message sizes.  So bump the buffer, right?  Well it isn’t quite that simple.  Below I will outline the configuration changes that have to be made to both the service and the client in order to accept messages that contain large arrays specifically.

The service configuration requires that the message size and array size need to be increased.  To be safe I increased the size of all the values.  You will note though that you will not normally see the binding spelled out in an auto-generated config file.You have to add the wsHttpBinding section.

<binding name="wsHttp" maxReceivedMessageSize="50000000">
<readerQuotas maxArrayLength="50000000" maxStringContentLength="50000000"/>
<service behaviorConfiguration="MyServiceBehavior"
<endpoint bindingConfiguration="wsHttp" address="" binding="wsHttpBinding" contract="IMyInterface">
<dns value="localhost" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

Since the WCF Test Client is rather limited to how data can be entered I ended up creating a Windows Forms application as a test harness.  The configuration for the client is included below.  Just like the service configuration I upped all of the values.

<binding name="WSHttpBinding_IQcsServices" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="50000000" maxReceivedMessageSize="50000000"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
<readerQuotas maxDepth="50000000" maxStringContentLength="50000000" maxArrayLength="50000000"
maxBytesPerRead="50000000" maxNameTableCharCount="50000000" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />

Hopefully these settings will help shortcut someone’s search to getting large WCF messages to work.

Posted on Monday, August 15, 2011 2:11 AM .NET , WCF | Back to top

Comments on this post: Sending Large Arrays With WCF

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Tim Murphy | Powered by: | Join free