Set up to implement WCF transport big data correctly

Source: Internet
Author: User
WCF can help us to transfer data. But has anyone ever met the need for high-volume data transfer? You can implement WCF to transfer big data as long as you make the correct settings.

When transmitting large data (>65535B) from the client to the WCF server, the discovery program jumps directly from the reference BeginInvoke to the EndInvoke, without entering the service's actual logic on the server, Suspicion is caused by excessive data exceeding the limit.

The problem is that the data I actually send is just received from the WCF server, and one goes, and the amount of data is not very different.

And then found that the client and the server are actually using different configurations, for the client, This setting is implemented in the System.ServiceModel section of the Servicereferences.clientconfig file that is automatically generated when you add ServiceReference to enable WCF to transfer Big data:

< bindings>
< basichttpbinding>
< binding name= "Basichttpbinding_wcfservice"
Maxbuffersize= "2147483647"
Maxreceivedmessagesize= "2147483647" >
< security mode= "None"/>
</binding>
</basichttpbinding>
</bindings> then apply the binding in the client section
Configuration:
< client>
< endpoint address= "/http
Localhost:22000/service/wcfservice.svc "
Binding= "BasicHttpBinding"
bindingconfiguration= "Basichttpbinding_wcfservice"
contract= "Wcfservicereference.wcfservice"
Name= "Basichttpbinding_wcfservice"/></client>
The maximum cache bytes and the maximum number of bytes accepted are specified in the binding, which is equal to the size of 2G! Unless a series of serials is passed, it is generally sufficient.

On the server side, the Web. config file, the bindings section is empty, and the service does not specify the Bindingconfiguration attribute, then they use the default size of 65535.

Problem finding, resolving WCF to transfer big data is easier:

In the Bindings section, add a new binding setting that specifies the maximum accepted data:

< bindings>
< basichttpbinding>
< binding name= "Largedatatransferservicesbinding"
Maxreceivedmessagesize= "2147483647"
messageencoding= "Text" transfermode= "Streamed"
sendtimeout= "00:10:00"/>
</basichttpbinding>
</bindings> to the appropriate service after
Specify the Bindingconfiguration property:
< service behaviorconfiguration=
"Server.Service.WcfServiceBehavior"
Name= "Server.Service.WcfService" >
< endpoint address= "" binding=
"BasicHttpBinding" bindingconfiguration=
"Largedatatransferservicesbinding"
contract= "Server.Service.WcfService"/>
< endpoint address= "Mex" binding=
"mexHttpBinding" contract= "IMetadataExchange"/>
</service>
This makes it possible to send large enough data from the client.

P.S.:

. NET can only pass 4M of files by default, so even if you set the configuration on both ends of WCF, or not the. NET limit, if you want to transfer large files, you also need to add the system.web section

< httpruntimemaxrequestlength= "102400"/>
Here the unit is KB, so you can transfer 100M files, fully solve the problem of WCF transmission big data. Of course, such a large file, preferably segmented transmission is better.

. NET can only pass 4M of files by default, so even if you set the configuration on both ends of WCF, or not the. NET limit, if you want to transfer large files, you also need to add the system.web section

< httpruntimemaxrequestlength= "102400"/>
Here the unit is KB, so you can transfer 100M files, fully solve the problem of WCF transmission big data. Of course, such a large file, preferably segmented transmission is better.

It is recommended that you do not transfer oversized data because it may cause your network to become clogged.
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.