将大型xml上载到WCF REST服务 - > 400错误请求

时间:2010-03-19 07:19:43

标签: c# wcf rest upload

我正在尝试将大型xml文件上传到REST服务...我已经尝试了在谷歌上的stackoverflow上指定的几乎所有方法,但我仍然无法找到我出错的地方....我无法上传更大的文件比64 kb!..

我指定了maxRequestLength:

<httpRuntime maxRequestLength="65536"/>

我的绑定配置如下:

<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>

在我的C#客户端,我正在执行以下操作:

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);
        }

客户端没有特殊配置...

我试过fiddler ...客户端正在发送一个正确的请求......但服务器立即响应400 ..

2 个答案:

答案 0 :(得分:8)

得到了我的回答!.... http://forums.asp.net/p/1375070/2887691.aspx ..... p!哇!....花了2天时间!#/ p>

答案 1 :(得分:0)

对于WCF SOAP,我所要做的就是:

 <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>