0

I have recently a new exception. When I try to call a method with a byte array in parameter I get a 413 error. I try to change maxBufferSize, maxReceivedMessageSize and maxBufferPoolSize but nothing had changed.

In my app.config of my application I have :

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="soap" 
             maxReceivedMessageSize="1116553600"
             maxBufferPoolSize="1116553600"
             maxBufferSize="1116553600"/>
  </basicHttpBinding>
  <wsHttpBinding>
    <binding name="mex" maxReceivedMessageSize="1116553600"
             maxBufferPoolSize="1116553600">
      <security mode="None" />
    </binding>
  </wsHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost:9804/ServiceBX.svc/soap"
    binding="basicHttpBinding" bindingConfiguration="soap" contract="ServiceReferenceBX.ServiceBX"
    name="soap" />
</client>
</system.serviceModel>

And in my web.config of my WCF service I have :

<system.serviceModel>
<services>
  <service name="BXSportWCFLib.ServiceBX" behaviorConfiguration="MyServiceBehavior">
    <endpoint name="rest" address="" binding="webHttpBinding" contract="BXSportWCFLib.ServiceBX" behaviorConfiguration="restBehavior" />
    <endpoint name="mex" address="mex" binding="mexHttpBinding" contract="BXSportWCFLib.ServiceBX" />
    <endpoint name="soap" address="soap" binding="basicHttpBinding" contract="BXSportWCFLib.ServiceBX" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="MyServiceBehavior" >
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="restBehavior">
      <webHttp  />
    </behavior>
  </endpointBehaviors>
</behaviors>
</system.serviceModel>

I see lot of things on this error but anything I try don't work.

First I like to know in wich file I must modify ?

I try to add bindings and modify my endoint but now when I execute my application I had a : "The requested service can't be activated"

<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<httpModules>
  <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>
<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="soap"
             maxReceivedMessageSize="116553600"
             maxBufferPoolSize="116553600"
             maxBufferSize="116553600">
      <readerQuotas maxStringContentLength="116533600" />
    </binding>
  </basicHttpBinding>
  <webHttpBinding>
    <binding name="web"
             maxReceivedMessageSize="116553600"
             maxBufferPoolSize="11653600"
             maxBufferSize="116553600">
      <readerQuotas maxStringContentLength="116533600" />
    </binding>
  </webHttpBinding>
</bindings>
<services>
  <service name="BXSportWCFLib.ServiceBX" behaviorConfiguration="MyServiceBehavior">
    <endpoint name="rest"
      address=""
      binding="webHttpBinding"
      bindingConfiguration="web"
      contract="BXSportWCFLib.ServiceBX"
      behaviorConfiguration="restBehavior" />
    <endpoint name="soap"
              address="soap"
              binding="basicHttpBinding"
              bindingConfiguration="soap"
              contract="BXSportWCFLib.ServiceBX" />
    <endpoint name="mex"
       address="mex"
       binding="mexHttpBinding"
       contract="IMetaDataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="MyServiceBehavior" >
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="restBehavior" >
      <webHttp  />
    </behavior>
  </endpointBehaviors>
</behaviors>
</system.serviceModel>

Thanks

Gobelet
  • 453
  • 2
  • 7
  • 18
  • 1
    Have a look at the accepted answer to [this question](http://stackoverflow.com/questions/14636407/maxreceivedmessagesize-not-fixing-413-request-entity-too-large) – derpirscher Mar 17 '16 at 21:16

2 Answers2

1

It sounds like you're receiving the error when calling the service, so you need to fix the config file for the service, not the client.

The posted config for the service does not specify any binding configurations, so WCF will use the default settings for the specified values. You need to a) define the binding configurations you want to use and b) assign them to the endpoints. Failure to do both will result in WCF still using the default values.

In your service config, add the following in the <system.serviceModel> section:

<bindings>
  <basicHttpBinding>
    <binding name="soap"
             maxReceivedMessageSize="116553600"
             maxBufferPoolSize="116553600"
             maxBufferSize="116553600">
      <readerQuotas maxStringContentLength="116533600" />
    </binding>
  </basicHttpBinding>
  <webHttpBinding 
    <binding name="web"
             maxReceivedMessageSize="116553600"
             maxBufferPoolSize="11653600"
             maxBufferSize="116553600">
      <readerQuotas maxStringContentLength="116533600" />
    </binding>
  </webHttpBinding>
</bindings>

Note that you need to specify the configuration for both basicHttpBinding and webHttpBinding.

Next, assign them to the correct endpoints via the bindingConfiguration attribute on the <endpoint> element:

<endpoint name="rest" 
          address="" 
          binding="webHttpBinding" 
          bindingConfiguration="web"
          contract="BXSportWCFLib.ServiceBX"
          behaviorConfiguration="restBehavior" />
<endpoint name="soap" 
          address="soap" 
          binding="basicHttpBinding" 
          bindingConfiguration="soap"
          contract="BXSportWCFLib.ServiceBX" />

Thirdly, your mex endpoint is specifying the wrong contract - it should be IMetaDataExchange:

<endpoint name="mex" 
           address="mex" 
           binding="mexHttpBinding" 
           contract="IMetaDataExchange" />

If you still get the 413 error, you will also want to adjust the maxRequestLength in <httpRuntime> element. This goes in the config file in the <system.webServer> section:

<system.web>
  <httpRuntime maxRequestLength="116533600" />
</system.web>

the default for maxRequestLength is 4 MB, but most likely the issue is with the values being used for the bindings on your service.

Tim
  • 28,212
  • 8
  • 63
  • 76
  • I try to add bindings and modify my endoint but now when I execute my application I had a : "The requested service can't be activated". I updated my question with the information. I can't see any other message error in the event viewer. – Gobelet Mar 18 '16 at 12:09
  • @Gobelet - Can you browse to the service address in a browser? Does the page come up? – Tim Mar 18 '16 at 19:40
  • This solution work for me up to 10MB data, but when i have tried to upload 34MB data than it throws "System.OutOfMemoryException". Any solution for that? – Abbas Panjwani Nov 25 '19 at 09:48
0

The solution work ! I had add bindings but I change the IMetaDataExchange and write BXSportWCFLib.ServiceBX and I have not the message "The requested service can't be activated"

<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<httpModules>
  <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>
<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="soap"
             maxReceivedMessageSize="116553600"
             maxBufferPoolSize="116553600"
             maxBufferSize="116553600">
      <readerQuotas maxStringContentLength="116533600" />
    </binding>
  </basicHttpBinding>
  <webHttpBinding>
    <binding name="web"
             maxReceivedMessageSize="116553600"
             maxBufferPoolSize="11653600"
             maxBufferSize="116553600">
      <readerQuotas maxStringContentLength="116533600" />
    </binding>
  </webHttpBinding>
</bindings>
<services>
  <service name="BXSportWCFLib.ServiceBX" behaviorConfiguration="MyServiceBehavior">
    <endpoint name="rest"
      address=""
      binding="webHttpBinding"
      bindingConfiguration="web"
      contract="BXSportWCFLib.ServiceBX"
      behaviorConfiguration="restBehavior" />
    <endpoint name="soap"
              address="soap"
              binding="basicHttpBinding"
              bindingConfiguration="soap"
              contract="BXSportWCFLib.ServiceBX" />
    <endpoint name="mex"
       address="mex"
       binding="mexHttpBinding"
       contract="IMetaDataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="MyServiceBehavior" >
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="restBehavior" >
      <webHttp  />
    </behavior>
  </endpointBehaviors>
</behaviors>
</system.serviceModel>
Gobelet
  • 453
  • 2
  • 7
  • 18