WCF REST - maxMessageSize exceeded - wcf

Here are parts of the configuration file:
<services>
<service name="MMC.API2.MMCApi" behaviorConfiguration="restBehaviorConfig">
<endpoint address="" binding="webHttpBinding" contract="MMC.API2.IMMCApi" behaviorConfiguration="web" bindingConfiguration="LargeData">
</endpoint>
<host>
<timeouts openTimeout="01:20:00" closeTimeout="01:20:00" />
</host>
</service>
</services>
...
<webHttpBinding>
<binding name="LargeData" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="32" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
</binding>
</webHttpBinding>
Problem:
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 fragments of the service’s binding configuration seem to be set ok, so you may want to look into the clients’ binding configurations to make sure they have similar settings for the readerQuotas and maxBuffer* settings.
Notes:
You may want to provide a bit more information about the overall environment/configuration.
If you haven’t already, enabling WCF trace logging may help you identify the issue.

It looks fine to me. Try to change the behavior configuration as below;
<serviceBehaviors>
<behavior name="web">
<dataContractSerializer ignoreExtensionDataObject="true" maxItemsInObjectGraph="2147483647" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceTimeouts transactionTimeout="00:10:00" />
<serviceThrottling maxConcurrentCalls="200" maxConcurrentSessions="100"
maxConcurrentInstances="100" />
</behavior>
</serviceBehaviors>

Related

WCF - When object to transfer has a list of more than 127 objects

i use WCF with Code First (VS 2012, .NET 4.0, WCF 5). Everything works fine unless i want to transfer an large object. It contains a list of many other objects. Every object has only small content. If this list is longer than 127 objects, i get an exception:
The server did not provide a meaningful reply; this might be caused by
a contract mismatch, a premature session shutdown or an internal
server error.
I found that out by reducing column count in database (try and error).
I use the following configuration on the client:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_****_Service" closeTimeout="00:00:10"
openTimeout="00:00:10" receiveTimeout="00:05:00" sendTimeout="00:05:00"
maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:8000/****" binding="netTcpBinding"
bindingConfiguration="****" contract="****"
name="NetTcpBinding_****Service">
<identity>
<userPrincipalName value="****" />
</identity>
</endpoint>
</client>
</system.serviceModel>
The server configuration looks as follows:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_****_Service" closeTimeout="00:00:10"
openTimeout="00:00:10" receiveTimeout="00:05:00" sendTimeout="00:05:00"
transferMode="Buffered" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
maxConnections="0" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="100000" maxStringContentLength="100000"
maxArrayLength="100000" maxBytesPerRead="100000" maxNameTableCharCount="100000" />
<reliableSession enabled="false" />
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="****">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_****_Service"
contract="****" />
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8000/****" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Please excuse the masking of some names. I need to avoid that one can draw inferences from these names about the project. :D
At first, set this property on server side (just for dev)
<serviceDebug includeExceptionDetailInFaults="true" />
that specifies whether to include managed exception information in the detail of SOAP faults returned to the client for debugging purposes.
It's sure there is something wrong when processing your request but you don't have any debug information. That's why you have to set this property. You can also turn on WCF Tracing but it's a bit more difficult.
WCF have many quotas : A quota is a hard limit that prevents the use of additional resources once the quota value is exceeded.
There are especially two quotas you need to be aware when sending large data : maxReceivedMessageSize and MaxItemsInObjectGraph.

WCF Service throwing a timeout error when using WcfTestClient

If I send parameters which will cause a lot of data to be pulled I get the following error:
The request channel timed out while waiting for a reply after 00:01:00. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout.
I have increased all of my timeouts. Is there something I have to do on the client side? I am wondering if this is because I am using wcftestclient? Do I need to adjust the operationTimeout?
My webconfig has the following:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="Basic" sendTimeout="12:00:00" receiveTimeout="12:00:00" openTimeout="00:10:00" closeTimeout="00:10:00"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
<readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="8192"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="CaseStudyBehavior" name="EDTFS.ADMS.CaseStudyService">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="Basic"
name="Basic"
contract="EDTFS.ADMS.ICaseStudyService" />
<endpoint address="mex"
binding="mexHttpBinding"
name="Metadata"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CaseStudyBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceTimeouts transactionTimeout="24:00:00"/>
<serviceThrottling maxConcurrentCalls="100" maxConcurrentInstances="100" maxConcurrentSessions="100"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
In the WCF Test Client you will find a node called Config File beneath your service. Right-click this and select Edit with SvcConfigEditor to increase timeout on the client.

WCF customBinding problem

I've been playing around with a pollingDuplex example that is driving me nuts. I'm using a customBinding to integrate the readerQuotas element and I keep getting the error: "Contract requires Duplex, but binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it."
Where is that BasicHttpBinding coming from when I am using customBinding ? I've checked countless examples and my configuration file matches what they had but it doesn't work. Can anyone help me with this ?
Thanks.
<configuration>
<system.serviceModel>
<extensions>
<bindingElementExtensions>
<add name="pollingDuplex" type="System.ServiceModel.Configuration.PollingDuplexElement, System.ServiceModel.PollingDuplex"/>
</bindingElementExtensions>
</extensions>
<bindings>
<customBinding>
<binding name="DBNotification" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00">
<httpsTransport maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"/>
<pollingDuplex duplexMode="MultipleMessagesPerPoll" maxPendingSessions="2147483647" maxPendingMessagesPerSession="2147483647"/>
<binaryMessageEncoding>
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binaryMessageEncoding>
</binding>
</customBinding>
</bindings>
<services>
<service name="AdminWebService" behaviorConfiguration="DBNotificationServiceBehavior">
<endpoint address="adminservice" binding="customBinding" bindingConfiguration="DBNotification" contract="AdminWebService.IAdminWebService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DBNotificationServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceThrottling maxConcurrentSessions="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
You're probably running into the "simplified configuration" problem - described in details at http://blogs.msdn.com/b/endpoint/archive/2009/11/09/common-user-mistake-in-net-4-mistyping-the-service-configuration-name.aspx. The "name" attribute in the <service> element must be the fully-qualified name of the service. Since your interface is AdminWebService.IAdminWebService, isn't your service name AdminWebService.AdminWebService? If so, fixing the name attribute should fix the issue.
Is it possible that httpGetEnabled="true" implies using BasicHttpBinding? Do you really need this feature? Does the error goes away if you comment this line?

wcf client config not getting values from server app.config

I have defined maxBufferSize = 2147483647, maxBufferPoolSize = 2147483647, maxReceivedMessageSize = 2147483647 in the server config file but when i generate client config file, values for all these parameters are defaulted in there and i have to edit them manually. This is how i generate the client config file
svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config net.tcp:/
/localhost:4365/MyService
Also since i am using maximum values in the maxBufferSize, maxBufferPoolSize, maxReceivedMessageSize and maxItemsInObjectGraph, is that going to hit the performance?
--Server config values--
<bindings>
<netTcpBinding>
<binding name="MySvc_InsecureTcp" closeTimeout="00:01:10" openTimeout="00:01:10" receiveTimeout="24.20:31:23.6470000"
listenBacklog="1000" maxConnections="1000" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="None">
<transport protectionLevel="None" />
</security>
</binding>
<binding name="MySvc_mexBinding" closeTimeout="00:01:10" openTimeout="00:01:10" receiveTimeout="24.20:31:23.6470000"
listenBacklog="1000" maxConnections="1000" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="None">
<transport protectionLevel="None" />
</security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="MyService">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceThrottling maxConcurrentCalls="30" maxConcurrentInstances="2147483647" maxConcurrentSessions="30" />
<serviceMetadata />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="MyNameSpace.MyService" behaviorConfiguration="MyService">
<endpoint address="" binding="netTcpBinding" contract="MyNameSpace.IMyService"
bindingConfiguration="MySvc_InsecureTcp" name="netTcpMySvc" >
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="netTcpBinding" contract="IMetadataExchange"
bindingConfiguration="MySvc_mexBinding" name="mexMySvc" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:4365/MyService"/>
</baseAddresses>
</host>
</service>
</services>
--After doing some more testing--
maxItemsInObjectGraph doesnt get included in the client config file. And if client is sending large objects, maxItemsInObjectGraph should be changed manually.
<behaviors>
<endpointBehaviors>
<behavior name="FASTServiceBehaviour">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
Not every configuration value defined on the service is passed to the client through metadata. Buffer sizes and reader quotas are one example because each participant in the communication can setup its own values - those values are defense against Denial of Service attack and can differ between service and client based on exchanged messages. For example if you want only upload large data sets you must set them correctly on the service but you don't need to modify them on the client. Downloading has reverse effect.
This is normal. Those properties are limited to that configuration file and don't carry across the service. Clients and servers can have different size limits, largely to help protect the sever against outrageously long requests (that the client might be expecting).

WCF Service Communication Exception Due to Parameter Size

I've got a WCF Web MEthod that takes in an XElement object as a parameter. For one of my XML files (sized at 600KB or so) this works just fine, however, for this bigger XML file (about 5MB) I get a CommunicationException right away.
I've already increased the message sizes for my binding. Below is the ServiceModel section of my web.config:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="BIMIntegrationWS.metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="BIMIntegrationWS.IntegrationService.customBinding0"
closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:10:00">
<binaryMessageEncoding>
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binaryMessageEncoding>
<httpTransport maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647" />
</binding>
</customBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service name="BIMIntegrationWS.BIMIntegrationWS" behaviorConfiguration="BIMIntegrationWS.metadataBehavior">
<endpoint address="" binding="customBinding" bindingConfiguration="BIMIntegrationWS.IntegrationService.customBinding0"
contract="BIMIntegrationWS.IBIMIntegrationService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
On the client, my ClientConfig looks like this:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CustomBinding_IBIMIntegrationService">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://localhost:1895/IntegrationService.svc"
binding="customBinding" bindingConfiguration="CustomBinding_IBIMIntegrationService"
contract="BIMIntegrationService.IBIMIntegrationService" name="customBindingEndpoint" />
</client>
</system.serviceModel>
Thanks in advance!
try to add following snippet into your web.config for the service application:
<system.web>
<httpRuntime maxRequestLength="16384" /> <!-- 16MB -->
</system.web>
When you host the service in web server you also have to tweak allowed request size for the web server.
Best regards,
Ladislav
Maybe your XElement has too many nodes/child elements, and you need to set the maxItemsInObjectGraph attribute under dataContractSerializer to something larger?
You probably need to change the values of the attributes of the <readerQuotas /> sub element of <binaryMessageEncoding />.
For more information, see:
http://msdn.microsoft.com/en-us/library/ms731325.aspx
http://forums.silverlight.net/forums/p/88704/205040.aspx
Update:
Can you try to increase the maxAllowedContentLength as described here:
http://social.msdn.microsoft.com/Forums/en/wcf/thread/e6e21132-ad3f-4135-8ab9-77923b099907
Do you know how to turn off VS host and to just deploy to IIS and give it a ping. Normal IIS 7 on your dev box will do just fine. You can still attach debugger etc, just won't have instantaneous F5 gratification but since your ocode is not dying on startup you don't need to see if from the fist line anyway :-)
If you would need to attach very early you could could make a mimimal method that doesn't tounch anything at all and just returns int constnat - just to bring up app pool so you can attach.