Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Transferring Large Data With WCF

0.00/5 (No votes)
23 Nov 2014 2  
Configuration settings need to be made to transfer large data with WCF

Introduction

In this article , i will explain what configuration settings we need to make to enable transferring of large amounts of data with WCF.

Setting The Configurations

The first configuration settings we need to make is in bindings section.We need to set maxBufferSize and maxReceivedMessageSize to '2147483647'.This is the max data we can transfer with WCF.

<bindings>
    <basichttpbinding>
        <binding allowcookies="false" bypassproxyonlocal="false" closetimeout="00:01:00" hostnamecomparisonmode="StrongWildcard" maxbufferpoolsize="524288" maxbuffersize="2147483647" maxreceivedmessagesize="2147483647" messageencoding="Text" name="BasicHttpBinding_ICom_ComContract" opentimeout="00:01:00" receivetimeout="00:10:00" sendtimeout="00:01:00" textencoding="utf-8" transfermode="Buffered" usedefaultwebproxy="true">
<readerquotas maxarraylength="16384" maxbytesperread="4096" maxdepth="32" maxnametablecharcount="16384" maxstringcontentlength="8192"></readerquotas>
        </binding>
    </basichttpbinding>
</bindings>

The second configuration change we need to make is to add two behaviors in configuratio, serviceBehaviors and endpointBehaviors. In both these behaviors we need to set datacontractSerializer maxItemsInObjectGraph value to '2147483647'

<behaviors>
    <servicebehaviors>
        <behavior name="ID_CodeService.D_ConversionServiceBehavior">
            <servicemetadata httpgetenabled="True">
                <servicedebug includeexceptiondetailinfaults="True">
                    <datacontractserializer maxitemsinobjectgraph="2147483647">
                    </datacontractserializer>
                </servicedebug>
            </servicemetadata>
        </behavior>
    </servicebehaviors>

    <endpointbehaviors>
        <behavior name="Behaviors.EndpointBehavior">
            <datacontractserializer maxitemsinobjectgraph="2147483647">
            </datacontractserializer>
         </behavior>
    </endpointbehaviors>
</behaviors>

You also need to add the behavior configuration information in end point

<endpoint address="" behaviorconfiguration="Behaviors.EndpointBehavior" binding="basicHttpBinding" bindingconfiguration="BasicHttpBinding_ID_ConContract" contract="ID_ConContract" name="BasicHttpBinding_ID_ConContract">
</endpoint>

Conclusion

There are also other techniques for sending large data with WCF, which I will explain in the next article.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here