<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>With Great Power comes Great Response.write("Ability") : IIS</title><link>http://blogs.msdn.com/phaniraj/archive/tags/IIS/default.aspx</link><description>Tags: IIS</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Astoria &amp; IIS , HTTP 400 Bad Request on Posting Large Payloads to an astoria service</title><link>http://blogs.msdn.com/phaniraj/archive/2008/10/06/astoria-iis-http-400-bad-request-on-posting-large-payloads-to-an-astoria-service.aspx</link><pubDate>Mon, 06 Oct 2008 05:35:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8977408</guid><dc:creator>PhaniRajuYN</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/phaniraj/comments/8977408.aspx</comments><wfw:commentRss>http://blogs.msdn.com/phaniraj/commentrss.aspx?PostID=8977408</wfw:commentRss><description>&lt;P&gt;We’ve seen this in the labs and also reported by our customers on the forums, If you try to post&amp;nbsp; a large amount of data to &lt;BR&gt;an astoria data service , you might receive a response code Http 400 Bad Request even though the response data is valid. &lt;BR&gt;&lt;BR&gt;An ADO.NET Data Service sits on top of Windows Communication Foundation , although most of the required plumbing is hidden away from you&amp;nbsp; ,&amp;nbsp; you can still see the effects in scenarios such as this .&lt;/P&gt;
&lt;H6&gt;Why do I get a generic 400 Bad Request in this case ?&lt;/H6&gt;When the request size ( including headers ) exceeds 64 K ( 65536 bytes ) , WCF chokes on the request as this request size is greater than the limit on the maximum size of the request the service can recieve and sends out a HTTP 400 Bad Request as the request is invalid. &lt;BR&gt;&lt;BR&gt;
&lt;H6&gt;How do I fix this ?&lt;/H6&gt;
&lt;P&gt;a)The maximum size of the request which a WCF service can process is controlled by the &lt;A href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.transportbindingelement.maxreceivedmessagesize.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.transportbindingelement.maxreceivedmessagesize.aspx"&gt;MaxReceivedMessageSize&lt;/A&gt; property on the WCF binding. &lt;BR&gt;The default value is 65536 ,exceeding which you get the 400 response code. &lt;BR&gt;&lt;BR&gt;In the web.config of the web site hosting the service , add the following node in the &amp;lt;System.ServiceModel&amp;gt; section. &lt;/P&gt;&lt;BR&gt;&lt;PRE class=darkcsharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;system.serviceModel&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt; 
&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;services&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt; 
  &lt;SPAN class=rem&gt;&amp;lt;!-- The name of the service --&amp;gt;&lt;/SPAN&gt; 
  &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;service&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="NorthwindService"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt; 
    &lt;SPAN class=rem&gt;&amp;lt;!-- you can leave the address blank or specify your end point URI --&amp;gt;&lt;/SPAN&gt; 
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;endpoint&lt;/SPAN&gt; &lt;SPAN class=attr&gt;address&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;="YourServiceEndpoint"&lt;/SPAN&gt; 
              &lt;SPAN class=attr&gt;binding&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="webHttpBinding"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;bindingConfiguration&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="higherMessageSize"&lt;/SPAN&gt; 
     &lt;SPAN class=attr&gt;contract&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;="System.Data.Services.IRequestHandler"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt; 
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;endpoint&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt; 
  &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;service&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt; 
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;services&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt; 
&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;bindings&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt; 
  &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;webHttpBinding&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt; 
    &lt;SPAN class=rem&gt;&amp;lt;!-- configure the maxReceivedMessageSize  value to suit the max size of &lt;/SPAN&gt;
&lt;SPAN class=rem&gt;         the request ( in bytes ) you want the service to recieve--&amp;gt;&lt;/SPAN&gt; 
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;binding&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="higherMessageSize"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;maxReceivedMessageSize&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;="MaxMessageSize"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt; 
  &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;webHttpBinding&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt; 
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;bindings&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt; 
&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;serviceHostingEnvironment&lt;/SPAN&gt; &lt;SPAN class=attr&gt;aspNetCompatibilityEnabled&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="true"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt; 
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;system.serviceModel&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;b) If hosted on IIS , the ASP.Net Request Size restriction can also cause a large request to be rejected, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; You will need to set the &lt;A href="http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.maxrequestlength.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.web.configuration.httpruntimesection.maxrequestlength.aspx"&gt;HttpRuntimeSection.MaxRequestLength&lt;/A&gt; Property. &lt;/P&gt;&lt;PRE class=darkcsharpcode&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;system.web&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt; 
  &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;httpRuntime&lt;/SPAN&gt; &lt;SPAN class=attr&gt;MaxRequestLength&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="ValueInKiloBytes"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;system.web&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;H6&gt;How do I Identify if the reason I am seeing a 400 Bad Request&amp;nbsp; is because of the request size ?&lt;/H6&gt;
&lt;P&gt;Identify if WCF is throwing an exception under the covers which is not being surfaced to you at the HTTP level. &lt;BR&gt;You can &lt;A title="Instructions on configuring WCF tracing" href="http://msdn.microsoft.com/en-us/library/ms733025.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ms733025.aspx"&gt;configure WCF tracing&lt;/A&gt; on the server-side to log the necessary information from the WCF layer. &lt;BR&gt;Once you have tracing setup and you reproduced the failure , check if the log contains one or both of these exception messages.&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;PRE class=darkcsharpcode&gt;System.ServiceModel.ProtocolException
&lt;SPAN class=str&gt;"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."
&lt;/SPAN&gt;
System.Web.HttpException
&lt;SPAN class=str&gt;"Maximum request length exceeded."&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;If you see that the log does contain this message , then you can be sure that the failure is because of the message size &lt;BR&gt;and apply this fix accordingly.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8977408" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Astoria/default.aspx">Astoria</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Debugging/default.aspx">Debugging</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Documentation/default.aspx">Documentation</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/IIS/default.aspx">IIS</category></item></channel></rss>