WCF Error 400 Bad Request when sending message bigger than 100mb - wcf

I made my first WCF service where I'm receiving data I have to process. The problem occurs when I send larger amounts, a 100mb soap message, of data at once, I get the reply Error 400 Bad Request.
I tried setting maxReceivedMessageSize, maxBufferSize, maxAllowedContentLength, readerQuotas that are referenced in other questions, but nothing seems to work or just makes the service not work at all.
These are the current settings in my web.config
<services>
<service name="RMQServices.RMQ_WS1" behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint address="webHttp" contract="RMQServices.RMQService" binding="basicHttpBinding" bindingConfiguration="myBasic" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="myBasic" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" sendTimeout="00:30:00">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" maxArrayLength="2147483647"/>
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
Am I still missing something in the config for it to work and accept larger requests?
EDIT:
If I send data via a service reference then it accepts even 1GB soap messages. But if I try to send it via HttpWebRequest with a prebuilt SOAP XML, then it still returns a Bad Request. So the problem seems to be in how I send the data.

make sure your client config also have these values
<client>
<endpoint address="[address]" binding="basicHttpBinding" bindingConfiguration="myBasic" contract="" name="Name" />
</client>
And then add
<bindings>
<basicHttpBinding>
<binding name="myBasic" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" sendTimeout="00:30:00">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" maxArrayLength="2147483647"/>
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
if this does not work, remove the security from the binding and then validate

Please try to add the following code snippets.
<behaviors>
<serviceBehaviors>
<behavior name="mybehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.web>
<httpRuntime maxRequestLength="2147483647" executionTimeout="3600" />
</system.web>
</configuration>
Also, Don’t forget to apply the configuration between the client-side and server-side (you should also add this configuration on both the client-side and server-side endpoints).
Feel free to let me know if the problem still exists.

Related

WCF SOAP service returns Not Found for a large request and works OK for a smaller one

I have a SilverLight application that calls WCF service by POST via SSL and sends large request. Everything works OK on a local machine with a self-signed certificate. Moreover, it works on a remote server but only for a small request. When the application make a POST request (using SOAP) for a big scope of data I get a CommunicationException: "The remote server returned an error: NotFound." The same use case on the local machine with absolutely the same web.config file (except of the sql connection string) works without the issue. It seems that the problem in the IIS configuration. I tried to investigate IIS logs but did not find any information about the requests as something before the logging kernel rejected the request. I have read a lot of articles where people propose different settings of the endpoints bindings, tried them but have not achieved success.
My configuration of the services is the next:
<system.web>
<httpRuntime maxRequestLength="2097151"/>
<!--...(other settings) -->
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
</system.webServer>
<system.serviceModel>
<services>
<!--... (other services)-->
<service name="SD.Web.Services.ClientUser.UserLayersService">
<endpoint address="soap"
binding="basicHttpBinding"
contract="SD.Web.Services.ClientUser.IUserLayersService" />
<endpoint address="json"
behaviorConfiguration="SD.Web.Services.AspNetAjaxBehavior"
binding="webHttpBinding"
contract="SD.Web.Services.ClientUser.IUserLayersService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding maxReceivedMessageSize="2097152"
maxBufferSize="2097152"
maxBufferPoolSize="2097152">
<security mode="Transport" />
</binding>
</webHttpBinding>
<basicHttpBinding>
<binding maxReceivedMessageSize="2097152"
maxBufferSize="2097152"
maxBufferPoolSize="2097152">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="SD.Web.Services.AspNetAjaxBehavior">
<webHttp defaultBodyStyle="Bare"
defaultOutgoingResponseFormat="Json"
automaticFormatSelectionEnabled="false"
faultExceptionEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
I found the answer using Fiddler 4. Reader quotas have to be set.
<bindings>
<webHttpBinding>
<binding maxReceivedMessageSize="2097152"
maxBufferSize="2097152"
maxBufferPoolSize="2097152">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<security mode="Transport" />
</binding>
</webHttpBinding>
<basicHttpBinding>
<binding maxReceivedMessageSize="2097152"
maxBufferSize="2097152"
maxBufferPoolSize="2097152">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>

Why do I still get "The maximum message size quota for incoming messages (65536) has been exceeded" error?

I'm encountering the well-known WCF error:
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.
After reading the top five Google results for this error, I still haven't any clue about what could be wrong with the configuration of my service/client.
What I have tried:
Setting maxReceivedMessageSize.
Setting maxBufferSize and maxBufferPoolSize.
Adding readerQuotas.
Ensuring the values are the same for the client and the server..
Ensuring binding configuration is specified by name.
Including the namespace in the service name.
Note that:
Small messages are transmitted correctly, but the error above occurs when sending a large message from the client to the server.
The message which is too large contains a ≈350 KB byte array (given that WCF is configured to encode to base64 the binary data).
It's a (1) two-way communication which (2) uses net TCP binding with (3) reliable session and (4) ordering set on (those four points differ from every example I've seen searching for the error).
The service is hosted by IIS Express installed with Visual Studio 2012.
This is my configuration. Any hint?
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<bindings>
<netTcpBinding>
<binding name="netTcpEndpoint"
receiveTimeout="00:10:00"
sendTimeout="00:10:00"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647"
maxBufferPoolSize="2147483647">
<readerQuotas maxDepth="2147483647"
maxArrayLength="2147483647"
maxStringContentLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<reliableSession ordered="true"
inactivityTimeout="00:10:00"
enabled="false" />
<security mode="None">
<message clientCredentialType="None" />
</security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="DebugOrientedBehavior"
name="DemoNamespace.PipeService">
<endpoint address="Default.svc"
binding="netHttpBinding"
name="TransportLayerServiceEndpoint"
contract="DemoNamespace.IPipeService" />
<host>
<baseAddresses>
<add baseAddress="http://example.com/Default.svc" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DebugOrientedBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
The client configuration is this one:
<bindings>
<netHttpBinding>
<binding name="TransportLayerServiceEndpoint"
receiveTimeout="00:10:00"
sendTimeout="00:10:00"
maxBufferPoolSize="2147483647"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647"
maxArrayLength="2147483647"
maxStringContentLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<reliableSession ordered="true"
enabled="false" />
<webSocketSettings transportUsage="Always" />
</binding>
</netHttpBinding>
</bindings>
<client>
<endpoint address="ws://example.com/Default.svc/Default.svc"
binding="netHttpBinding"
bindingConfiguration="TransportLayerServiceEndpoint"
contract="PipeServiceReference.IPipeService"
name="TransportLayerServiceEndpoint" />
</client>
Your service config appears to have an issue - you specify netHttpBinding for the service endpoint with no bindingConfiguration, and you have a configuration defined for netTcpBinding (but apparently not used). Relevant service portion of your config here:
<endpoint address="Default.svc"
binding="netHttpBinding"
name="TransportLayerServiceEndpoint"
contract="DemoNamespace.IPipeService" />
Note that there is no bindingConfiguration value set. I would suggest adding the binding configuration defined in the client to your service config, and then updating the service endpoint to use that binding:
<endpoint address="Default.svc"
binding="netHttpBinding"
bindingConfiguration="TransportLayerServiceEndpoint"
name="TransportLayerServiceEndpoint"
contract="DemoNamespace.IPipeService" />
Currently your service is using the default values for netHttpBinding, which is probably the reason you're still getting the error.

How to read streams in parallel at client from a WCF Service Method, without blocking each other?

I'm trying to create a download application, in which there would be four or more download queues using which a user can download files from the server. What would be best possible solution to accomplish this without letting the queues blocking each other. I'm starting every download queue in a different background thread which reports progress to the WPF Client UI as the bytes are getting downloaded from service. But, a new download queue blocks any previously running download Queue. I've tried to search a lot on google and StackOverflow but, still not able to resolve the issue
Methodology Applied:
We are using Windows Azure Service Bus to connect to our WCF service using the NetTcpRelayBinding.
Client Side Configuration:
<system.serviceModel>
<bindings>
<!-- Application Binding -->
<netTcpRelayBinding>
<binding name="default"
connectionMode="Hybrid"
maxReceivedMessageSize="2147483647"
transferMode="Streamed"
closeTimeout="01:00:00"
openTimeout="00:30:00"
sendTimeout="infinite"
receiveTimeout="infinite"
maxBufferPoolSize="2147483647"
maxBufferSize="2147483647"
maxConnections="500"
listenBacklog="200">
<security mode="None"/>
<readerQuotas maxBytesPerRead="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" />
<reliableSession enabled="false" ordered="true" />
</binding>
</netTcpRelayBinding>
</bindings>
<client>
<!-- Application Service -->
<endpoint name="RelayEndpoint" contract="DDMInterface.IBaseService" binding="netTcpRelayBinding" bindingConfiguration="default" address="" />
</client>
Service Configuration:
<system.serviceModel>
<bindings>
<!-- Application Binding -->
<netTcpRelayBinding>
<binding name="default"
connectionMode="Hybrid"
maxReceivedMessageSize="2147483647"
transferMode="Streamed"
closeTimeout="01:00:00"
openTimeout="00:30:00"
sendTimeout="infinite"
receiveTimeout="infinite"
maxBufferPoolSize="2147483647"
maxBufferSize="2147483647"
maxConnections="500"
listenBacklog="200">
<security mode="None"/>
<readerQuotas maxBytesPerRead="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" />
<reliableSession enabled="false" ordered="true" />
</binding>
</netTcpRelayBinding>
</bindings>
<services>
<!-- Application Service -->
<service name="DDMService.DDMBaseService" behaviorConfiguration="ThrottleBehavior">
<endpoint name="RelayEndpoint"
contract="DDMInterface.IBaseService"
binding="netTcpRelayBinding"
bindingConfiguration="default"
address=""/> <!--behaviorConfiguration="defaultBehavior"-->
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ThrottleBehavior">
<serviceThrottling maxConcurrentCalls="2147483647" maxConcurrentInstances="2147483647" />
<!--maxConcurrentSessions="2147483647"-->
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="defaultBehavior">
<dispatcherSynchronization asynchronousSendEnabled="true"/>
</behavior>
</endpointBehaviors>
</behaviors>
Service Behavior:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]
public class DDMBaseService : IBaseService
{
I've been banging my head since past 2 weeks on this problem and still not able to resolve it. Please help me finding a proper approach by suggesting links or solutions.
Please ask any more information if required.
Thanks in advance...
UPDATE
I tried debugging the code more and more and found that the downloads were indeed working in parallel but were not getting reflected at the UI. I corrected that problem.

WCF Streaming not able to transfer large files

I am making a WCF Service for transfering files. I have only basic WCF understanding and followed the MSDN tutorial: WCF Tutorial
I started using byte arrays for transfering the files but as soon as the files got a little big (100kb was enough) it would fail with bad request.
I followed another guide and changed to streaming with messages, and it works with small files as well but fails with bigger ones like the old version. I suspect the fault lies in my config file as the one generated by svcutil.exe doesn't say anything about streaming.
This is my clients app.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IDocPublisher" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="200000000" maxReceivedMessageSize="200000000"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="200000000" maxStringContentLength="200000000" maxArrayLength="200000000"
maxBytesPerRead="200000000" maxNameTableCharCount="200000000" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8000/ServiceModelSamples/docPublisherWebService/docPublisher"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IDocPublisher"
contract="IDocPublisher" name="WSHttpBinding_IDocPublisher">
<identity>
<userPrincipalName value="Emil-PC\Emil" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
And this is the servers app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"
httpHelpPageEnabled="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="serviceBehavior"
name="DocPublisher">
<endpoint address="http://localhost:8000/ServiceModelSamples/docPublisherWebService"
name="basicHttpStream"
binding="basicHttpBinding"
bindingConfiguration="httpLargeMessageStream"
contract="IDocPublisher" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="httpLargeMessageStream"
maxReceivedMessageSize="200000000"
maxBufferSize="200000000"
transferMode="Streamed"
messageEncoding="Mtom" />
</basicHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
Try to increase send timeout and reader quotas on client side, set buffer size on server side.
Turns out the config files weren't the real problem, the problem was that the servers app.config was never used as the msdn tutorial doesn't use app.config but creates the endpoints in the main method.

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.