Posts
415
Comments
233
Trackbacks
42
Sending Large Arrays With WCF

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.

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

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.

<system.serviceModel>
<bindings>
<wsHttpBinding>
<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"
allowCookies="false">
<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" />
</security>
</binding>
</wsHttpBinding>
</bindings>

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 Print
Comments
No comments posted yet.

Post Comment

Title *
Name *
Email
Comment *  
 

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

www.flickr.com
Tag Cloud