2

I am posting data into a IIS web server using C#.

I have used XML and the mode and I am getting an 'Bad Request Error' when posting very long data in one field. For example,

<Field1>TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT.......<Field1>

I have already modified my Web.Config

<webHttpEndpoint>
   <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="21474836" maxBufferSize="21474836"  maxBufferPoolSize="21474836" ></standardEndpoint>
          </webHttpEndpoint>

What else do I need to do to make this work?

   <system.web>
        <authentication mode="Forms" />
        <compilation debug="true" targetFramework="4.0">
            <assemblies>
                <add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            </assemblies>
        </compilation>
        <httpRuntime maxRequestLength="204800" executionTimeout="12000" requestValidationMode="2.0" requestPathInvalidCharacters="" />
    </system.web>
    <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"></serviceHostingEnvironment>
        <standardEndpoints>
            <webHttpEndpoint>
                <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="21474836" maxBufferSize="21474836" maxBufferPoolSize="21474836"></standardEndpoint>
            </webHttpEndpoint>
        </standardEndpoints>
    </system.serviceModel>
DafaDil
  • 2,463
  • 6
  • 23
  • 33
  • If you're using JavaScript to post it back then make sure your web.config is set to accept big json blobs. [The JSON request was too large to be deserialized](http://stackoverflow.com/questions/10966328/the-json-request-was-too-large-to-be-deserialized) – Dustin Kingen May 08 '13 at 19:16
  • I am using a C# client and XML – DafaDil May 08 '13 at 19:17
  • How big, exactly, is the request body (use Fiddler to easily get that number). – EricLaw May 08 '13 at 23:01
  • You're missing a / in the closing tag of Field1 - could it be something that simple? – Jasmine May 08 '13 at 23:06
  • Nope, this is just a typo, I create the XML using XmlDocument – DafaDil May 08 '13 at 23:08

2 Answers2

1

You need to fix this value in the web.config for all requests, not just for WCF services, as you have done...

<httpRuntime maxRequestLength="1234" executionTimeout="1200" />

You probably need to increase that number. This is for the HttpRuntime which happens first - all requests are subject to the rules defined by this tag. The request limit you set for WCF services will only be applied if the request passes this check (and others) first.

Jasmine
  • 4,003
  • 2
  • 29
  • 39
  • I have updated the web.config file as displayed on the question, it still gives me that error. Have I modified this correctly? – DafaDil May 08 '13 at 22:00
  • You're getting a 400: Bad Request? That means the syntax of your request wasn't correct - not the length. Please post your code that submits your request - the problem is probably there. Also take a look at this: http://stackoverflow.com/questions/8507853/wcf-rest-4-0-put-post-delete-not-working-400-bad-request?rq=1 – Jasmine May 08 '13 at 22:46
  • The thing is it works when the string is shorter. I have now posted the code. Many Thanks – DafaDil May 08 '13 at 22:52
  • I think your content-type needs to be application/xml. – Jasmine May 08 '13 at 23:00
  • Tried it but same problem :( – DafaDil May 08 '13 at 23:02
  • Try this code change, and if it doesn't work, please post the text of the request from Fiddler. change this line-->(string content = "xml="+xmlDoc.InnerXml;) – Jasmine May 08 '13 at 23:08
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/29620/discussion-between-dafadil-and-jasmine) – DafaDil May 08 '13 at 23:14
0

I fixed it by adding the readerQuotas into the standardEndpoint

<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="21474836" maxBufferSize="21474836"  maxBufferPoolSize="21474836" >
          <readerQuotas maxStringContentLength="2048000" maxArrayLength="2048000"  maxDepth ="65000"/>
        </standardEndpoint>
      </webHttpEndpoint>
        </standardEndpoints>
DafaDil
  • 2,463
  • 6
  • 23
  • 33