When sending large data (> 65535b) from the client to the WCF serverProgramDirectly jump from begininvoke of reference to endinvoke, but does not enter the actual service logic of the server. It is suspected that the data exceeds the limit.
Error message: the remote server returns an unexpected response: (400) Bad request.
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 > < Binding Name = " Basichttpbinding_wcfservice " Maxbuffersize = " 2147483647 " Maxcompute edmessagesize = " 2147483647 " > < Security Mode = " None " /> </ Binding > </ Basichttpbinding > </ Bindings >
Then apply binding configuration in the client section:
<Client> <EndpointAddress="Http: // localhost: 22000/service/wcfservice. SVC"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 bindings to specify 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 = " Mexico httpbinding " Contract = " Imetadataexchange " /> </ Service >
In this way, you can send large enough data from the client.
P.s .:
. By default, only files of 4 MB can be uploaded. Therefore, although the configuration at both ends of the WCF is set, the file cannot be uploaded.. add
<Httpruntimemaxrequestlength="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.