Solve the problem that the amount of data transmitted by WCF is too large, and the amount of data transmitted by wcf is too large.

Source: Internet
Author: User
Tags xml reader

Solve the problem that the amount of data transmitted by WCF is too large, and the amount of data transmitted by wcf is too large.

 

I wrote a WCF interface today and passed the test. When I call it with someone else, the remote server returns an error: (413) Request Entity Too Large! I remember this error also occurred when I wrote it before. The general solution is to set the limit for receiving the maximum message on the server to a greater value. However, the specific configuration nodes and parameters are a bit forgotten. I found some information on the Internet to correct them and passed the test. The main configuration is as follows:

When the server returns an error with too much data, modify the Server Configuration:

Add a binding configuration on the bindings node to specify the maximum number of received data, mainly the value of the maxcompute edmessagesize attribute:

 

<binding name="LargeDataTransferServicesBinding" maxReceivedMessageSize="2147483647"          messageEncoding="Text" transferMode="Streamed" sendTimeout="00:10:00" />

 

Then, specify the bindingConfiguration attribute for the corresponding Service and point to the previous binding configuration. Note that because it is a server configuration, it is configured in the services node, the contract node is your service contract name:

<services>      <service name="Huazhu.Certificate.WCFService.SyncDataService">               <endpoint address="" binding="basicHttpBinding" bindingConfiguration="LargeDataTransferServicesBinding" name="XXX" contract="Huazhu.Certificate.WCFService.ISyncDataService" />      </service>    </services>


After configuration, test the task and report another error, which is roughly as follows:

An exception occurs when the formatter tries to deserialize the message: an error occurs when deserializing the request message body that operates "PushMasterData. When reading XML data, the maximum length of string content exceeds the limit (8192 ). You can add this quota by changing the MaxStringContentLength attribute of the XmlDictionaryReaderQuotas object used when creating an XML reader. Row 1, position 2177

Well, now it should be that the data can be received. It indicates that a MaxStringContentLength attribute value should be set. It seems that the default read length is not enough, then, the configuration of the modified binding node is as follows:

<binding name="LargeDataTransferServicesBinding" maxReceivedMessageSize="2147483647"          messageEncoding="Text" transferMode="Streamed" sendTimeout="00:10:00" >          <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>        </binding>


After testing, the call is successful. However, if there are many WCF interfaces provided, each Service must be configured, so that there are too many duplicates. Is it simpler? The following code indicates that you only need to configure a binding node without the name attribute. You do not need to configure the previous Service. In my understanding, the name attribute is not configured, this is equivalent to the default binding. This default binding is used unless the configuration is set separately.

<binding   closeTimeout="00:10:00" receiveTimeout="00:20:00" sendTimeout="00:20:00"          maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"/>


This configuration is also applicable to the client configuration of WCF. You only need a binding. If you do not understand other node attributes in this article, please search for them online. There is a lot of information.

 

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.