Pass big data through WCF

Source: Internet
Author: User

When the client transfers large data (> 65535b) to the WCF server, the client reports an error. Remote servers do not respond.

The problem is that the data I actually sent was just received from the WCF server. As a result, the data volume does not differ much.

Then we found that the client and the server actually use different configurations. for the client, the system. servicemodel section in the servicereferences. clientconfig file automatically generated when adding servicereference has the following settings:

 
<Bindings> <basichttpbinding> <binding name = "basichttpbinding_wcfservice" maxbuffersize = "2147483647" maxcompute edmessagesize = "2147483647"> <security mode = "NONE"/> </binding> </basichttpbinding> </bindings>

Then apply binding configuration in the client section:

 
<Client> <endpoint address = "http: // localhost: 22000/service/wcfservice. SVC "binding =" basichttpbinding "bindingconfiguration =" basichttpbinding_wcfservice "Contract =" wcfservicereference. wcfservice "name =" basichttpbinding_wcfservice "/>

</Client>

The maximum number of cached bytes and the maximum number of accepted bytes are specified in the binding, which is equivalent to 2 GB! Unless you pass on a complete series, it is generally enough.

On the server side, the bindings section in the web. config file is empty, and the service does not specify the bindingconfiguration attribute. Therefore, they use the default 65535 size.

It is easier to locate the problem:

Add new binding settings in bindings to specify the maximum data reception:

 
<Bindings> <basichttpbinding> <binding name = "inherit" maxcompute edmessagesize = "2147483647" messageencoding = "text" transfermode = "streamed" sendtimeout = "00:10:00"/> </basichttpbinding> </bindings>

Then, specify the bindingconfiguration attribute for the corresponding service:

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

In this way, you can send large enough data from the client.

P.s .:

By default, Asp.net can only upload 4 m Files. Therefore, although the configuration at both ends of the WCF is set, it is still unable to exceed.. add

 
<Httpruntime maxrequestlength = "102400"/> here, the unit is KB. In this way, MB of files can be uploaded. Of course, it is better to perform multipart transmission for such a large file.
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.