Settings for transferring big data through WCF

Source: Internet
Author: User

When sending large data (> 65535b) from the client to the WCF serverProgramDirectly jump from begininvoke of reference to endinvoke, but does not enter the actual service logic of the server. It is suspected that the data exceeds the limit.

Error message: the remote server returns an unexpected response: (400) Bad request.

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> <EndpointAddress="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  = " Largedatatransferservicesbinding " 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 = " Mexico httpbinding " Contract  = " Imetadataexchange " /> </  Service  > 

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

P.s .:

. By default, only files of 4 MB can be uploaded. Therefore, although the configuration at both ends of the WCF is set, the file cannot be uploaded.. add

 
<Httpruntimemaxrequestlength="102400"/>

The unit here is kb, so that 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.