WCF maxReceivedMessageSize cannot exceed 4215

I want to set maxReceivedMessageSize in the App.config of the WCF client.

If maxReceivedMessageSize is equal to or less than 4215, it works fine. Although, setting it to 4216 or any value above it, the default value of 65536 is accepted.

enter image description here

enter image description here

My customer code

<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_IConexaApiServic" maxReceivedMessageSize="4216" /> </basicHttpBinding> </bindings> <client> <endpoint address="http://svsr02.conexa.local/HelloService/ConexaApiService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IConexaApiServic" contract="ConexaApiService.IConexaApiService" name="BasicHttpBinding_IConexaApiService" /> </client> </system.serviceModel> </configuration> 

And the server reference code

 <basicHttpBinding> <binding name="BasicHttpEndpoint_MPSAPIServic" maxReceivedMessageSize="2000000"> <security mode="TransportWithMessageCredential" /> </binding> <binding name="BasicHttpEndpoint_HelloService" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxReceivedMessageSize="2000000"> </binding> </basicHttpBinding> <service name="IIS_test123.HelloService"> <endpoint address="ConexaApi" binding="basicHttpBinding" bindingConfiguration="BasicHttpEndpoint_HelloService" contract="IIS_test123.IHelloService"></endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="http://localhost:8733/API/ConexaApiService" /> </baseAddresses> </host> </service> </services> 

Any idea how to fix this?

+6
source share
1 answer

This can be explained. If you look at your exceptions:

  • System.ServiceModel.CommunicationException - exception thrown from the client side. It has maxReceivedMessageSize on the client side. Everything is good.
  • FaultException: this exception is a SOAP error that propagates service exceptions to the client application. ( http://www.codeproject.com/Articles/799258/WCF-Exception-FaultException-FaultContract ). Thus, this exception occurs on the part of the service! The value of maxReceivedMessageSize is the default and does not match maxReceivedMessageSize in your server configuration. The address that you connect to in your client is the service address not configured by maxReceivedMessageSize, not the ConexaApi endpoint address, which is configured with maxReceivedMessageSize = "2000000". This is why you get the default 65536.

And 4215 should be the size of your message if you think that the exception does not occur if you increase it.

+1
source

Source: https://habr.com/ru/post/982319/


All Articles