WCF Request Entity Too Large - wcf

Try to save image through my WCF service. I noticed that with small file size 3619 it works fine but with big file size 52857 , it doesn't.
Here is my config file
<bindings>
<basicHttpBinding>
<binding name="MaxbasicHttpBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="None"/>
</binding>
</basicHttpBinding>
</bindings>

If you give a binding a name, it has to be explicitly set on your service with the bindingConfiguration property. Using bindingConfiguration="MaxbasicHttpBinding"on your service configuration (see below) should work. If you do not have a service configuration, then removing name="MaxbasicHttpBinding" from your definition will make it apply to all endpoints.
<services>
<service name="Your.ServiceName">
<endpoint name="Your.ServiceName.EndpointName"
binding="basicHttpBinding"
bindingConfiguration="MaxbasicHttpBinding"
contract="Your.Service.Contract" />
</service>
</services>

Related

WCF Service error "Maximum message size quota for incoming message as been exceeded"

I have a WCF Service library project who request a large recordset from a database and returns it. This error pop everytime in the WCF Test Client. I changed the MaxReceivedMessageSize to a large value but it doesn't seem to take it. Here the Web.Config
<client>
<endpoint address="http://localhost:8000/SAPIntranet" binding="basicHttpBinding"
bindingConfiguration="Binding_SAPIntranet" contract="SAPIntranet"
name="SAPIntranet" kind="" endpointConfiguration="" />
</client>
<bindings>
<basicHttpBinding>
<binding name="Binding_SAPIntranet" openTimeout="00:02:00" maxBufferPoolSize="20000000"
maxBufferSize="20000000" maxReceivedMessageSize="20000000">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>
</basicHttpBinding>
</bindings>
Error message always gives the default value (65535).
I guess there is something I'm doing wrong, but can't figure it out.
Thanks for your time and help
MaxReceivedMessageSize setting takes effect on the server-side, we should apply the binding configuration on the service endpoint. The above configuration applies only to the client service endpoint. Please refer to the below service configuration.
<services>
<service name="WcfService1.Service1">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="mybinding" contract="WcfService1.IService1">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="mybinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
Feel free to let me know if there is anything I can help with.

The remote server returned an unexpected response: (400) Bad Request. if the transferring string size is more than 48KB

i have a self hosted wcf service, below are the config details of both service and client, it works fine if the transferred string/data size is less than 48KB but if the size is more then it throws the title error.
i am new to wcf and searched this issue, found many earlier reports which ask to configure the buffer size but its not working in my case.
Thanks.
Server config details
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding_DeployConfiguration" transferMode="Streamed" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" receiveTimeout="00:30:00" sendTimeout="00:30:00">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="None"></security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="Default" name="CPConfigDeploy.DeployConfiguration">
<endpoint address=""
binding="basicHttpBinding"
contract="CPConfigDeploy.IDeployConfiguration"/>
</service>
</services>
</system.serviceModel>
and below is the client config details
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_DeployConfiguration" transferMode="Streamed" maxReceivedMessageSize="21474836480" maxBufferPoolSize="21474836480" maxBufferSize="10485760" receiveTimeout="00:30:00" sendTimeout="00:30:00">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://10.140.188.117:8080/deploy" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_DeployConfiguration"
contract="IDeployConfiguration" name="BasicHttpBinding_IDeployConfiguration"/>
</client>
</system.serviceModel>
You don't assign the binding configuration you defined to the service endpoint. In your service's config you have:
<endpoint address=""
binding="basicHttpBinding"
contract="CPConfigDeploy.IDeployConfiguration"/>
Since there's no bindingConfiguration value set, the system uses the default values for basicHttpBinding.
What you need is this:
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="basicHttpBinding_DeployConfiguration"
contract="CPConfigDeploy.IDeployConfiguration"/>
Then your service will pick up the larger values you specified for the binding configuration.

WCF returns 404 for large request, maxReceivedMessageSize="2147483647"

Our WCF service on large request returns following error:
"System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at http://xxx.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. ---> System.Net.WebException: The remote server returned an error: (404) Not Found.
For small requests everything works fine and I am getting correct response from WCF service, the issue is only with large requests.
Settings on the client are as follow:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ITestService" openTimeout="00:05:00" sendTimeout="00:05:00" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" >
<readerQuotas maxDepth="2147483647" maxBytesPerRead="2147483647" maxArrayLength="2147483647" maxStringContentLength="2147483647"
maxNameTableCharCount="2147483647"/>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:33333/TestService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITestService" contract="TestService.ITestService" name="BasicHttpBinding_ITestService" />
</client>
</system.serviceModel>
The settings of the WCF service:
<bindings>
<basicHttpBinding>
<binding maxReceivedMessageSize="2147483647" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483646" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
What can be the issue?
In this case, the error was not with WCF but with the IIS settings.
The Message was to large for IIS, I have added "maxAllowedContentLength" to the web.config on the server.
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2200000000"/>
</requestFiltering>
</security>
The error message was misleading.
In my case, it was not working even after trying all solutions and setting all limits to max. In last I found out that a Microsoft IIS filtering module Url Scan 3.1 was installed on IIS/website, which have it's own limit to reject incoming requests based on content size and return "404 Not found page".
It's limit can be updated in %windir%\System32\inetsrv\urlscan\UrlScan.ini file by setting MaxAllowedContentLength to the required value.
For eg. following will allow upto 300 mb requests
MaxAllowedContentLength=314572800

The remote server returned an error: (413) Request Entity Too Large

I know this is a redundant question, I am getting the error while I am uploading the a file which is more than 100 KB.
The remote server returned an error: (413) Request Entity Too Large.
I am posting the content to a WCF Service (64 bit environment). Am aware this should have been resolved with managing maxReceivedMessageSize and relevant behaviours but unfortunately its not.
Below is my configurations :-
Client
<binding allowCookies="false" bypassProxyOnLocal="false" closeTimeout="00:01:00" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" name="BasicHttpBinding_ICandidateManagementService" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:11:00" textEncoding="utf-8" transferMode="Streamed" useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message algorithmSuite="Default" clientCredentialType="UserName"/>
</security>
</binding>
<behavior name="CandidateBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
<endpoint address="http://localhost:62368/CandidateManagementService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICandidateManagementService" contract="MMJ.ServiceContracts.ServiceContract.ICandidateManagementService" name="BasicHttpBinding_ICandidateManagementService" behaviorConfiguration="CandidateBehavior" />
Service
<services>
<service name="BasicHttpBinding_ICandidateManagementService" behaviorConfiguration="CandidateBehavior">
<endpoint contract="MMJ.ServiceContracts.ServiceContract.ICandidateManagementService" binding="basicHttpBinding" address="" bindingConfiguration="BasicHttpBinding_ICandidateManagementService"/>
</service>
I have seen possibly everything available and still cant solve this issue. have also tried using below configuration, but still no change...
<serverRuntime uploadReadAheadSize="500000000" maxRequestEntityAllowed="500000000"/>
Kindly help!
Service binding Config (its same as client)
<binding allowCookies="false" bypassProxyOnLocal="false" closeTimeout="00:01:00" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" name="BasicHttpBinding_ICandidateManagementService" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:11:00" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="32" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message algorithmSuite="Default" clientCredentialType="UserName"/>
</security>
</binding>
To give more insight below is the fiddlers finding :-
Request Count: 1 Bytes Sent: 85,719 (headers:697; body:85,022)
Bytes Received: 10,129 (headers:254; body:9,875)
At last my problem is resolved after struggling a lot. I had a flaw in my Service config, which was not giving me any runtime or compile time error as it was not even recognizing the config.
My Service Config was :-
<services>
<service name="BasicHttpBinding_ICandidateManagementService" behaviorConfiguration="CandidateBehavior">
<endpoint contract="MMJ.ServiceContracts.ServiceContract.ICandidateManagementService" binding="basicHttpBinding" address="" bindingConfiguration="BasicHttpBinding_ICandidateManagementService"/>
</service>
I have the "Name" property which is not fully qualified name of my service, and thus the configuration I used was not even considered and thus was taking default 65KB for maxReceivedMessageSize.
I have updated it and its working like a charm.
<services>
<service name="MMJ.Services.CandidateManagementService">
<endpoint contract="MMJ.ServiceContracts.ServiceContract.ICandidateManagementService" binding="basicHttpBinding" address="" bindingConfiguration="BasicHttpBinding_ICandidateManagementService"/>
</service>
Also, have a look at this post for more reference. I know this was a silly mistake, and thanks everyone for putting an effort to fix.
You're posting the data to the server, so updating the client settings won't help. The client is not the one receiving the large message, the server is.
Looking at your client endpoint:
Shouldn't the bindingConfiguration be
bindingConfiguration="BasicHttpBinding_ICandidateManagementService"
Instead of
bindingConfiguration="BasicHttpBinding_IAdminService"

WCF Service Binding taking default values instead of custom values

I have build an APi which is a WCF Service. In the web.config for the service i have specified a custom bindong looking like this:
<bindings>
<wsHttpBinding>
<binding name="FxBinding"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"
closeTimeout="00:20:00"
openTimeout="00:20:00"
receiveTimeout="00:20:00"
sendTimeout="00:20:00"
messageEncoding="Mtom">
<readerQuotas
maxDepth="64"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<security mode="None"></security>
</binding>
</wsHttpBinding>
</bindings>
Telling the configuration to use the binding i have specified by setting the "name" attribute in the endpoint tag:
<services>
<service name="Dba.Admanager.Api.ListingServiceContract" behaviorConfiguration="Dba.Admanager.Api.ListingServiceContractBehavior">
<endpoint address="" binding="wsHttpBinding" name="FxBinding" contract="Dba.Admanager.ApplicationController.Api.IListingServiceContract">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
See. When i create an web reference to the service in VS2008 a app.config are generated.
In this app.config the binding used, should be the one specified above. But in the app.config is a default binding with default values in the "maxArrayLength" for instance.
<bindings>
<wsHttpBinding>
<binding name="FxBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="">
<extendedProtectionPolicy policyEnforcement="Never" />
</transport>
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://l-aar-00424012.corp.ebay.com/Admanager.Api/ListingServiceContract.svc"
binding="wsHttpBinding" bindingConfiguration="FxBinding" contract="WCFListingServiceContract.IListingServiceContract"
name="FxBinding">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
I can see that the client is using the FxBinding configuration, but why on earth all the values are default, i dont understand. Can anubody give at at clue on how to customize the binding-values and make it reflect on the "client"-part?
If i change the values manualle in the app.config i get the desired effect, but every time the webreference is updated, VS just adds a new binding with the default values.
Information such as maxArrayLength is not part of the WSDL, so the client cannot infer it and just takes default values.
As Darin already mentioned - since those binding parameters aren't part of the interoperable metadata between service and client, they can't be automagically picked up by the client when you create a new client proxy.
What you could do is this:
define your binding configurations in a separate config file and reference that on the server - i.e. put everything inside <bindings> into bindings.config and then reference it from your server side web.config or app.config:
<system.serviceModel>
<bindings configSource="bindings.config" />
</system.serviceModel>
Then copy that bindings.config to your client side and do the same thing there in your app.config.
Note: yes, Visual Studio will complain about the "configSource" not being defined and all - but that's just a flaw in the VS intellisense for config files. Trust me - it works - I use it everyday in production systems! Every configuration section in .NET has a "configSource" attribute!
With this method, you create one file that contains those binding configurations for your system and you can use it on both the server and the client side.