uploading large xml to WCF REST service -> 400 Bad request

旧街凉风 提交于 2019-12-07 06:10:53

问题


I am trying to upload large xml files to a REST service... I have tried almost all methods specified on stackoverflow on google but I still cant find out where I am going wrong....I cannot upload a file greater than 64 kb!..

I have specified the maxRequestLength :

<httpRuntime maxRequestLength="65536"/>

and my binding config is as follows :

<bindings>
  <webHttpBinding>
    <binding name="RESTBinding" maxBufferSize="67108864" maxReceivedMessageSize="67108864" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
    </binding>   
  </webHttpBinding>
</bindings>

In my C# client side I am doing the following :

WebRequest request = HttpWebRequest.Create(@"http://localhost.:2381/RepositoryServices.svc/deviceprofile/AddDdxml");

        request.Credentials = new NetworkCredential("blah", "blah");
        request.Method = "POST";
        request.ContentType = "application/xml";
        request.ContentLength = byteArray.LongLength;


        using (Stream postStream = request.GetRequestStream())
        {
            postStream.Write(byteArray, 0, byteArray.Length);
        }

There is no special configuration done on the client side...

I have tried fiddler...The client is sending a proper request...But the server immediately responds with a 400..


回答1:


Got my answer!....http://forums.asp.net/p/1375070/2887691.aspx.....phew!....spent 2 days behind this!




回答2:


For WCF SOAP all I had to do was:

 <binding name="uploadFilesBasicHttpBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" receiveTimeout="00:10:10" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00">
    <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
    <security mode="TransportWithMessageCredential">
        <message clientCredentialType="UserName"/>
    </security>
  </binding>


来源:https://stackoverflow.com/questions/2475578/uploading-large-xml-to-wcf-rest-service-400-bad-request

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!