The ability of WCF to transmit data is constrained by a number of factors, and should be aware of the following configuration if a program fails to invoke a WCF service because of the large amount of data that needs to be transferred:
1. MaxReceivedMessageSize: Gets or sets the maximum size of messages that can be received on a channel configured with this binding.
Predefined bindings, such as basichttpbinding, typically have maxreceivedmessagesize properties, and custombinding need to be defined in transport.
Example code:
<Bindings> <custombinding> <binding name="CustomBinding"> <binarymessageencoding> </binarymessageencoding> <HttpTransport MaxReceivedMessageSize="2147483647"> </HttpTransport> </binding> </custombinding> <BasicHttpBinding> <binding name="Basicbinding" MaxReceivedMessageSize="2147483647"></binding> </BasicHttpBinding></Bindings>
Many places on the web say you should set MaxBufferSize at the same time (Gets or sets the maximum size of the buffer that is used to receive messages from the channel. ), as explained on MSDN:
The value of the MaxBufferSize property differs from its importance, depending on whether the message is buffered or streamed on the channel that receives the message:
For buffered transports, (Transfermode is set to Buffered). The value is always equal to the value specified by maxreceivedmessagesize .
For stream Transport (Transfermode is set to Streamed), the SOAP header must be buffered to generate the message. The body can be streamed as needed. In this case, MaxBufferSize is less than or equal to maxreceivedmessagesize, where maxreceivedmessagesize restricts the size of the entire message (header and body), and MaxBufferSize only limits the size of the SOAP header. ”
It is visible that setting this property is not necessary for the default buffered transport.
2. Readerquotas: Gets or sets the complexity constraints of SOAP messages that can be processed by endpoints configured with this binding.
This property is a xmldictionaryreaderquotaselement type, and it is generally necessary to set the property's maxarraylength,maxstringcontentlength and MaxDepth properties.
Example code:
<Bindings> <custombinding> <binding name="CustomBinding"> <binarymessageencoding> <Readerquotas Maxarraylength="2147483647" Maxstringcontentlength="2147483647" maxDepth=" the"/> </binarymessageencoding> <HttpTransport MaxReceivedMessageSize="2147483647"> </HttpTransport> </binding> </custombinding> <BasicHttpBinding> <binding name="Basicbinding" MaxReceivedMessageSize="2147483647"> <Readerquotas Maxarraylength="2147483647" Maxstringcontentlength="2147483647" maxDepth=" the"/> </binding> </BasicHttpBinding></Bindings>
3. Maxitemsinobjectgraph: Gets the maximum number of items in the object graph to serialize or deserialize.
This property belongs to the DataContractSerializer class and needs to be configured in the Behavior section under Servicebehaviors.
Example code:
<Behaviors> <servicebehaviors> <Behavior name="Wcf4BigData.Web.BigDataServiceBehavior"> <Servicemetadata httpgetenabled="true"/> <Servicedebug Includeexceptiondetailinfaults="false"/> <DataContractSerializer Maxitemsinobjectgraph="2147483647"/> </Behavior> </servicebehaviors></Behaviors>
These are some of the WCF properties that you might need to set when transferring large amounts of data, and most of the sample code sets the value of the property to the maximum allowable value, but it does not guarantee that WCF has the ability to transmit such a large amount of data. In addition, these properties generally need to be set on both the server and client side, but if you use a Silverlight client, some properties such as Readerquotas are not supported.
4. maxRequestLength: Gets or sets the maximum size of the request.
If WCF is hosting IIS, the ability of WCF to transmit data is also constrained by the Httprunttime setting, which may require the maxRequestLength attribute to be httprunttime (in the system.web section) at the same time. The maxRequestLength property represents the maximum size of the request, in kilobytes. The default size is 4096 KB (4 MB), and the maximum allowable value is 2097151.
Example code:
< HttpRuntime maxRequestLength="2097151"/>
Using the above configuration for testing, it is successful to get 10 million strings of length 10 from the WCF side. Each length of 10 string encoding about 32 bytes, so that the successful transmission of data has been more than 300M, is not a small number, if the amount of data than this is still larger, even if the speed is not enough to meet the requirements, then need to consider other solutions.
Considerations for configuring WCF when large data volumes are transferred