Sending Large SOAP messages in WCF
This is just a quick tip. Remember SOAP runs over HTTP – and just changing the SOAP configuration (basicHttpBinding or wsHTTPBinding configuration) is not enough for sending large SOAP messages in WCF. The Client refers to whatever code is calling the WCF service. It could be a Silverlight app, it could be your web layer (MVC code). It could be a desktop app. Or it could just be a browser calling the WCF service endpoint directly (in which case you have no control over the config file).
Server (Service) Web.config
You need to set BOTH the maxReceivedMessageSize and the maxStringContentLength in web.config (in your Services layer project) – as shown below.
<binding name="AgathaRequestProcessorBinding" maxReceivedMessageSize="2147483647" receiveTimeout="00:30:00" sendTimeout="00:30:00">
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647"/>
Client Config (web.config or app.config)
You also need to set the same the maxReceivedMessageSize on the client (provided you have a .NET client that you can modify). You DO NOT need the maxStringContentLength on the client.
<binding name="AgathaRequestProcessorBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
receiveTimeout="00:30:00" sendTimeout="00:30:00">
Having modified the server and client config files, you may think you are all done. However, if your client is about to send a large file over to the service, it needs to specify that in its maxRequestLength (inside httpRuntime element in its config file)
Also needed on Client side (whatever is calling the WCF Services code, e.g. the MVC layer) config
Example – to send a 10 MB size SOAP request, you need to set maxRequestLength to 10240 (default is 4096 – for 4MB)
<!-- this is needed in conjunction with the maxStringContentLength to send large XML strings over http (soap)-->
<httpRuntime targetFramework="4.5" maxRequestLength="10240" executionTimeout="120"/>
Summary
While it seems that WCF configuration should be all that is needed for sending large SOAP messages, the HTTPRuntime element also enters the picture (though only on the client side). With the above three configuration settings (maxStringContentLength and maxReceivedMssageSize on server, maxReceivedMessageSize on client and maxRequestLength (httpRuntime) on client), you should be all set to send (client) and handle (server) large SOAP requests.
Anuj holds professional certifications in Google Cloud, AWS as well as certifications in Docker and App Performance Tools such as New Relic. He specializes in Cloud Security, Data Encryption and Container Technologies.
Anuj Varma – who has written 1217 posts on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.
No Comments Yet
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Leave a Reply