Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF maxReceivedMessageSize cant set over 4215

Tags:

c#

wcf

app-config

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

If the maxReceivedMessageSize equals or is smaller then 4215 it works fine. Though when setting it to 4216 or any value above it, the default value of 65536 is taken.

enter image description here

enter image description here

My Client 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 relavant Server 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?

like image 547
Wintermule Avatar asked Feb 11 '15 11:02

Wintermule


People also ask

What is the MaxReceivedMessageSize WCF max value?

MaxReceivedMessageSize = 1000000; The value of this property can also be set in the configuration file.

What is the default MaxReceivedMessageSize for WCF service?

By default, it is 65536.


1 Answers

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

  • System.ServiceModel.CommunicationException is an exception thrown from client side. It has the maxReceivedMessageSize from the client side. Everything is fine.
  • FaultException: this exception is a SOAP fault that propagate the exceptions from the service to the client application. ( http://www.codeproject.com/Articles/799258/WCF-Exception-FaultException-FaultContract). So this exception is actually coming from the service side! The maxReceivedMessageSize is the default value, and does not correspond to the maxReceivedMessageSize in your server configuration. The address you are connecting to in your client is the service address, not configured maxReceivedMessageSize, and not the endpoint address ConexaApi which is configure with maxReceivedMessageSize="2000000". That' s why you are getting the default 65536.

And 4215 must be the size of your message if you consider that the exception does not raise if you increase it.

like image 66
Nat Acha Avatar answered Oct 20 '22 12:10

Nat Acha