Error 400 (invalid request): maxReceivedMessageSize is not counted for my WCF service

There are several related questions on SO (almost the same name), none of them helped me fix my problem. Please do not close my question as a duplicate before reading it. Thanks.

I am currently using WCF to publish a web service (SOAP, HTTP). It is currently deployed in IIS Express. My problem is that I cannot use the services of my client. My client gets an HTTP Error 400 Bad request exception.

Then I activated the server-side trace to see what was actually happening, this is what I get:

enter image description here

I translated the error message into English: The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element. The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element. .

Pretty self-evident, actually. Since my SOAP message is pretty heavy, it probably exceeds the 64K limit.

I decided to expand this limit in the binding configuration. So here is my web.config (server side):

 <services> <service name="MyServiceName"> <endpoint binding="basicHttpBinding" bindingConfiguration="MyBindingConfiguration" bindingNamespace="http://my_namespace" contract="XXX.IMyContract" /> </service> </services> <bindings> <basicHttpBinding> <binding name="MyBindingConfiguration" allowCookies="true" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647"> <readerQuotas maxDepth="32" maxArrayLength="2147483647" maxStringContentLength="2147483647" /> </binding> </basicHttpBinding> </bindings> 

As you can see, all sizes are set to int.MaxValue .

I also changed my app.config client, here it is:

 <bindings> <basicHttpBinding> <binding name="MyBindingName" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <security mode="None"> <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> <message clientCredentialType="UserName" algorithmSuite="Default" /> </security> </binding> </basicHttpBinding> </bindings> <client> <endpoint address="http://localhost:8083/myAddress.svc" binding="basicHttpBinding" bindingConfiguration="MyBindingName" contract="IMyContract" name="MyBindingName" /> </client> 

Then I redeployed my service and the problem was still there ( HTTP 400, Bad request on the client side + MaxReceivedMessageSize limited to 65536 on the server side).

Then I checked my service with a very small SOAP message: everything is fine. . So the problem is that my message is more than 64 KB.

Yesterday I spent 2 hours trying to figure out what was the problem with my configuration ... Probably something obvious, but I can not find ...

I knew a lot about this problem, in 95% of cases the developer forgot to specify the bindingConfiguration attribute at the service endpoint. As you can see in my web.config above, this is normal for me.

Then, I found https://stackoverflow.com/a/312969/

As the author said in his question, setting the binding configuration name to string.Empty β€œfixes” the problem:

 <services> <service name="MyServiceName"> <endpoint binding="basicHttpBinding" bindingConfiguration="" ... <bindings> <basicHttpBinding> <binding name="" ... 

When using the default binding, everything works fine. I cannot just fix my problem with this workaround, because I need to specify several different binding configurations in the same web.config.

I recreate the question here because the conditions are not the same: my service is not self-service, but hosted on IIS Express (or IIS 7.5, verified, same problem).

I found a similar problem here with self-service, and the problem was related to this feature. So I think there is something different between these two SO questions.

I assume that something is clearly wrong in my configuration, but I cannot find that. Any help was appreciated.

+2
source share
2 answers

At first glance, everything seems beautiful - just a point: the <service name="....."> attribute must match exactly for your fully functional service implementation class (including all namespaces, etc.) - is that what it is? ?

I ask because you have contract="XXX.IMyContract" indicating the namespace, but your <service name="...."> attribute does not have any namespace that is targeted.

+4
source

Try the following web configuration settings:

  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> <standardEndpoints> <webHttpEndpoint> <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" crossDomainScriptAccessEnabled="true" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="4194304" /> </webHttpEndpoint> </standardEndpoints> <bindings> <webHttpBinding> <binding> <readerQuotas maxStringContentLength="2147483647"/> </binding> </webHttpBinding> </bindings> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true" /> </system.webServer> 
0
source

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


All Articles