Click here to Skip to main content
15,895,142 members
Articles / Configuration
Tip/Trick

Transferring Large Data With WCF

Rate me:
Please Sign up or sign in to vote.
3.80/5 (3 votes)
23 Nov 2014CPOL 25.6K   8   7
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.

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

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

XML
<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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
SuggestionOther Optimizations Pin
CoderStu25-Nov-14 1:03
CoderStu25-Nov-14 1:03 
GeneralRe: Other Optimizations Pin
Suniil Kumar Pal25-Nov-14 3:19
Suniil Kumar Pal25-Nov-14 3:19 
GeneralMy vote of 2 Pin
prince782723-Nov-14 21:38
prince782723-Nov-14 21:38 
GeneralRe: My vote of 2 Pin
Suniil Kumar Pal24-Nov-14 3:09
Suniil Kumar Pal24-Nov-14 3:09 
QuestionHow much data (buffer size 2147483647) in MB will you specify? Pin
Vikenesh23-Nov-14 20:40
Vikenesh23-Nov-14 20:40 
AnswerRe: How much data (buffer size 2147483647) in MB will you specify? Pin
Suniil Kumar Pal24-Nov-14 3:07
Suniil Kumar Pal24-Nov-14 3:07 
GeneralRe: How much data (buffer size 2147483647) in MB will you specify? Pin
Vikenesh24-Nov-14 18:02
Vikenesh24-Nov-14 18:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.