WCF can help us to transfer data. But has anyone ever encountered a need for high-capacity data transmission? WCF can transfer large data as long as the correct settings are made.
When transferring large data from the client to the WCF server (>65535b), the discovery program jumps directly from the reference BeginInvoke to the EndInvoke, not into the service-side actual logic, Suspicion is caused by too much data exceeding the limit.
The problem is that the data I actually send is just received from the WCF server, and one way, there is not much difference in the amount of data.
It is then found that the client and the server are actually using different configurations for the client, This setting is implemented in the System.ServiceModel section of the Servicereferences.clientconfig file that is automatically generated when adding servicereference to implement WCF transfer large data:
< bindings>
< basichttpbinding>
< binding name= "Basichttpbinding_wcfservice"
Maxbuffersize= "2147483647"
Maxreceivedmessagesize= "2147483647" >
< security mode= "None"/>
</binding>
</basichttpbinding>
</bindings> then apply binding in the client section.
Configuration:
< client>
< endpoint address= "http://
Localhost:22000/service/wcfservice.svc "
Binding= "BasicHttpBinding"
bindingconfiguration= "Basichttpbinding_wcfservice"
contract= "Wcfservicereference.wcfservice"
Name= "Basichttpbinding_wcfservice"/></client>
Specify the maximum cache bytes and the maximum number of bytes to accept in the binding, equivalent to 2G in size! Unless you pass a whole series, it's usually enough.
On the server side, the Web.config file, the bindings section is empty, and the service does not specify the Bindingconfiguration attribute, they use the default size of 65535.
Problem found, it is easier to solve the WCF transfer large data:
Add a new binding setting in the Bindings section to specify the maximum acceptance data:
< bindings>
< basichttpbinding>
< binding name= "Largedatatransferservicesbinding"
Maxreceivedmessagesize= "2147483647"
messageencoding= "Text" transfermode= "streamed"
sendtimeout= "00:10:00"/>
</basichttpbinding>
</bindings> to the corresponding service after
Specify the Bindingconfiguration property:
< 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 allows you to send large enough data from the client.
P.S.:
. NET can only transfer 4M of files by default, so even if you set the configuration on both sides of WCF, it is not the limit of. NET, so if you want to transfer large files, you need to add the system.web section
< httpruntimemaxrequestlength= "102400"/>
The unit here is KB, so you can transfer 100M files, fully solve the WCF transmission of large data problems. Of course, such a large file, preferably segmented transmission is better.
. NET can only transfer 4M of files by default, so even if you set the configuration on both sides of WCF, it is not the limit of. NET, so if you want to transfer large files, you need to add the system.web section
< httpruntimemaxrequestlength= "102400"/>
The unit here is KB, so you can transfer 100M files, fully solve the WCF transmission of large data problems. Of course, such a large file, preferably segmented transmission is better.
It is not recommended to transmit too large data because it may cause your network to jam.