【问题标题】:webHttpBinding having issue with posting 1MB xml filewebHttpBinding 在发布 1MB xml 文件时遇到问题
【发布时间】:2014-06-05 21:17:10
【问题描述】:

我有用于 wcf 服务的 webHttpBinding。无法将大型 xml 文件 (1MB) 发布到服务,出现以下错误 RequestEntityTooLarge (413) 不是以下之一:OK (200)、Created (201)、Accepted (202)、NonAuthoritativeInformation (203)、NoContent (204)、重置内容 (205)、部分内容 (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(); 语句失败。

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

【问题讨论】:

    标签: c# xml wcf visual-studio


    【解决方案1】:

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

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

    【讨论】:

    • 我在同一个 wcf 项目下创建了多个服务,它们都在 Global.asax.cs 文件中动态启动..请帮助..谢谢
    • 也许您应该显示您在 .asax.cs 文件中的代码
    • 签出这个帖子stackoverflow.com/questions/19380352/…adriano-repetti回答你熟悉Proxy的
    • 该帖子与代理服务器身份验证有关,错误代码为 407.. 我收到 RequestEntityTooLarge 错误代码 (413).. 这是一个大文件,小文件无法正常工作:(
    • 有没有办法通过 Buffer Chuncks 流式传输大文件?也许
    【解决方案2】:

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

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

    name 属性用于端点配置,但与使用的绑定配置无关。在您的 &lt;endpoint&gt; 元素中添加:

    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>
    

    【讨论】:

    • 我这样做了,现在出现以下错误.. 在服务启动中.. System.ServiceModel.dll 中发生了“System.ArgumentException”类型的未处理异常附加信息:提供的 URI 方案“http” ' 是无效的;预期'https
    • 您定义的绑定已将安全模式设置为传输 - 使用 https 或将安全模式设置为无。
    猜你喜欢
    • 2015-11-02
    • 2013-04-10
    • 1970-01-01
    • 2018-02-26
    • 1970-01-01
    • 1970-01-01
    • 2015-02-24
    • 1970-01-01
    • 2021-08-17
    相关资源
    最近更新 更多