Home > Backend Development > C#.Net Tutorial > Correct settings to implement WCF to transmit big data

Correct settings to implement WCF to transmit big data

巴扎黑
Release: 2016-12-20 09:20:19
Original
1886 people have browsed it

WCF can help us transmit data. But has anyone ever encountered a need for large-capacity data transfer? As long as the correct settings are made, WCF can transmit big data.

When transmitting large data (>65535B) from the client to the WCF server, it was found that the program jumped directly from BeginInvoke of Reference to EndInvoke without entering the actual logic of Service on the server. It is suspected that the data is too large and exceeds the limit. caused.

The problem is that the data I actually sent was just received from the WCF server. There is not much difference in the amount of data coming and going.

Then I discovered that different configurations are actually used on the client and server. For the client, there is such a setting under the system.serviceModel section in the ServiceReferences.ClientConfig file automatically generated when adding ServiceReference to implement WCF transmission of big data:

< bindings>
< basicHttpBinding>
< binding name="BasicHttpBinding_WcfService"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
< / 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 cache bytes and the maximum accepted words are specified in the Binding The number of sections is equivalent to the size of 2G! Unless a whole series of TV series is transmitted, it is usually enough.

On the server side, in the Web.config file, the Bindings section is empty, and the Service does not specify the bindingConfiguration attribute, so they use the default size of 65535.

The problem is found and it is easier to solve the problem of WCF transmitting big data:

Add a new Binding setting in the Bindings section and specify the maximum accepted data:

< bindings>
< basicHttpBinding>
< binding name="LargeDataTransferServicesBinding "
maxReceivedMessageSize="2147483647"
messageEncoding="Text" transferMode="Streamed"
sendTimeout="00:10:00" />
< /basicHttpBinding>
< /bindings> Then specify the corresponding Service
bindingConfiguration attribute:
< 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>
This way you can send enough from the client Big data.

P.S.:

.net can only transfer 4M files by default, so even though the configuration of both ends of Wcf is set, it still cannot exceed the limit of .net, so if you want to transfer large files, you need to go under the System.Web section Plus

< httpRuntimemaxRequestLength="102400" />
The unit here is KB, so that 100M files can be transferred, which fully solves the problem of WCF transmitting big data. Of course, for such a large file, it is best to transfer it in segments.

.net can only transfer 4M files by default, so even though the configuration of both ends of Wcf is set, it still cannot exceed the limit of .net, so if you want to transfer large files, you need to add

under the System.Web section < httpRuntimemaxRequestLength="102400" />
The unit here is KB, so that 100M files can be transferred, which fully solves the problem of WCF transmitting big data. Of course, for such a large file, it is best to transfer it in segments.

It is recommended not to transmit too large data as it may cause congestion on your network.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template