Examples of using WCF to transmit large data

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>
& Lt; 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 = "www.2cto.com"
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 the Bindings section. TB specifies 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 = "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"/>
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.
Author: tbwshc
 

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.