webHttpBinding 在发布 1MB xml 文件时有问题 [英] webHttpBinding having issue with posting 1MB xml file

查看:19
本文介绍了webHttpBinding 在发布 1MB xml 文件时有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have webHttpBinding for wcf service. Can not post large xml file (1MB) to service getting following error RequestEntityTooLarge (413) is not one of the following: OK (200), Created (201), Accepted (202), NonAuthoritativeInformation (203), NoContent (204), ResetContent (205), PartialContent (206)"} System.Exception {System.ArgumentOutOfRangeException}

这里是 wcf 服务的配置..

Here is configuration for wcf service..

<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(); 语句上失败.

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

Any idea how to fix this in development and production ?

推荐答案

您在配置文件中定义了 webHttpBinding,但您的服务并未使用它,因为您没有在 webHttpBinding代码>bindingConfiguration 属性.

You defined a webHttpBinding in your config file, but it's not being used by your service because you did not specify it in the bindingConfiguration attribute.

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

name 属性用于端点配置,但与使用的绑定配置无关.在您的 元素中添加:

The name attribute is used for the endpoint configuration, but has no bearing on the binding configuration used. In your <endpoint> element add this:

bindingConfiguration="webHttpBinding_LTLInboundService"

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

so your defined endpoint will use the values for the binding specified, not the default.

最终端点如下所示:

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

这篇关于webHttpBinding 在发布 1MB xml 文件时有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆