【问题标题】:.NET WCF Soap Service returns no response because of request size由于请求大小,.NET WCF Soap 服务不返回响应
【发布时间】:2019-04-09 18:41:09
【问题描述】:

我有一个 WCF Soap 服务,我试图从 SoapUI 和我的 Java 程序中调用它。我正在从 Java 端读取 Excel 文件并将其发送到 .NET 端。

Excel 文件有 37 列,最多可包含 100 行。我一一阅读所有行并将它们添加到列表中。在列表的一项中,单行中每个单元格的键值对象列表。

这是我的问题。该服务适用于有限的行数。我查看了可以成功发送的最大内容长度,即 65536。如果我发送内容长度超过 65536 的请求,服务将不返回任何内容。

如果我从 Java 项目发送请求,我会收到以下错误:

无法发送消息。;嵌套异常是 org.apache.cxf.transport.http.HTTPException: HTTP response '400: Bad Request' 当与...通信时...

在 .NET 项目的 web.config 文件中,我知道请求大小没有限制。

Web.Config

<system.web>
  <compilation targetFramework="4.0" debug="true"/>
  <httpRuntime/>
</system.web>

SoapUI 我的请求

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:pas="http://schemas.datacontract.org/2004/07/..." xmlns:pas1="http://schemas.datacontract.org/2004/07/..." xmlns:arr="http://schemas.microsoft.com/2003/10/...">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:ListSegments>
         <!--Optional:-->
         <tem:request>
            <!--Optional:-->
            <pas:UserName>tst</pas:UserName>
            <!--Optional:-->
            <pas1:DetailList>
               <!--Zero or more repetitions:-->
               <arr:ArrayOfKeyValueOfstringstring>
                  <!--Zero or more repetitions:-->
                  <arr:KeyValueOfstringstring>
                     <arr:Key>No</arr:Key>
                     <arr:Value>1</arr:Value>
                  </arr:KeyValueOfstringstring>
                  ....
               </arr:ArrayOfKeyValueOfstringstring>
               <arr:ArrayOfKeyValueOfstringstring>
                  <!--Zero or more repetitions:-->
                  <arr:KeyValueOfstringstring>
                     <arr:Key>No</arr:Key>
                     <arr:Value>2</arr:Value>
                  </arr:KeyValueOfstringstring>
                  ....
               </arr:ArrayOfKeyValueOfstringstring>
               ....
            </pas1:DetailList>
          <tem:request>
       <tem:ListSegments>
    <soapenv:Body>
</soapenv:Envelope>

【问题讨论】:

    标签: .net wcf soap


    【解决方案1】:

    这些限制有默认值。其中之一是 maxAllowedContentLength,它的默认值应该是 30000000,大约是 28.6MB。所以你可能遇到的不是这个。

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

    可能是maxReceivedMessageSize 通常在 web.config 的绑定部分中设置,而您似乎没有。也许它们是在代码中设置的?

    <basicHttpBinding>
      <binding maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" 
           maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      </binding>
    </basicHttpBinding>
    

    也许有一个更高“级别”的配置文件设置了默认值。这可能是 machine.config 文件或另一个 Web.config,具体取决于设置(如果它在 IIS 中运行)。

    【讨论】:

    • 非常感谢。添加 basicHttpBinding 部分后,我的问题解决了。也感谢您提供有关所有这些可能性的信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-11
    • 2010-11-03
    • 2011-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多