webHttpBinding在发布1MB xml文件时遇到问题

时间:2014-06-05 21:17:11

标签: c# xml wcf visual-studio

我有wcf服务的webHttpBinding。无法发布大型xml文件(1MB)以获取跟踪错误RequestEntityTooLarge(413)不是以下之一:OK(200),Created(201),Accepted(202),NonAuthoritativeInformation(203),NoContent(204), ResetContent(205),PartialContent(206)“} System.Exception {System.ArgumentOutOfRangeException}

这是wcf服务的配置..

<service name="abc" >
      <endpoint address="http://localhost:8741/LTLInboundService/" binding="webHttpBinding"                  behaviorConfiguration="WebHttpBehaviour" contract="abc" name="webHttpBinding_LTLInboundService" >
        </endpoint>
</service>

   <webHttpBinding>
       <binding name="webHttpBinding_LTLInboundService" closeTimeout="00:10:00"
        openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
        allowCookies="false" bypassProxyOnLocal="false" 
    hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" 
    maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
        transferMode="Streamed" 
        useDefaultWebProxy="true">
       <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
    maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
    maxNameTableCharCount="2147483647" />
       <security mode="Transport">
          <transport clientCredentialType="None"/>
       </security>
        </binding>
    </webHttpBinding>   

这是失败的代码..

using (HttpClient client = new HttpClient("http://localhost:8741/LTLInboundService" + "/SendCompletionReports"))
{
    // Initalise a response object
    HttpResponseMessage response = null;

    string responseFilePath = Path.Combine(@"c:\Samir\abc.xml");
    string xmlData = System.IO.File.ReadAllText(responseFilePath);

    // Create a content object for the request
    HttpContent content = HttpContent.Create(xmlData, Encoding.UTF8, "text/xml");

    // Make the request and retrieve the response
    response = client.Post("http://localhost:8741/LTLInboundService" + "/SendCompletionReports", content);

    // Throw an exception if the response is not a 200 level response
    response.EnsureStatusIsSuccessful();

    // Retrieve the content of the response for processing
    response.Content.LoadIntoBuffer();
}

response.EnsureStatusIsSuccessful();声明失败。

知道如何在开发和生产中解决这个问题吗?

2 个答案:

答案 0 :(得分:0)

结帐此网站并注意他们如何在安全部分下配置此部分 Dealing with Larger Files in Asp.NET

<system.webServer>
  <security>
    <requestFiltering>
      <requestLimits maxAllowedContentLength="2147483648" />
    </requestFiltering>
  </security>
</system.webServer>

答案 1 :(得分:0)

您在配置文件中定义了webHttpBinding,但您的服务未使用它,因为您未在bindingConfiguration属性中指定它。

<service name="abc" >
  <endpoint address="http://localhost:8741/LTLInboundService/"
            binding="webHttpBinding"
            behaviorConfiguration="WebHttpBehaviour" contract="abc" 
            name="webHttpBinding_LTLInboundService" >
  </endpoint>
</service>

name属性用于端点配置,但与使用的绑定配置无关。在<endpoint>元素中添加以下内容:

bindingConfiguration="webHttpBinding_LTLInboundService"

因此,您定义的端点将使用指定绑定的值,而不是默认值。

最终端点如下所示:

<service name="abc" >
  <endpoint address="http://localhost:8741/LTLInboundService/"
            binding="webHttpBinding"
            bindingConfiguration="webHttpBinding_LTLInboundService"
            behaviorConfiguration="WebHttpBehaviour" contract="abc" 
            name="webHttpBinding_LTLInboundService" >
  </endpoint>
</service>