调用 SOAP 时,“底层连接已关闭:预期保持活动状态的连接已被服务器关闭”

问题描述 投票:0回答:1

在调用另一个 WSDL 服务时,有时会出现错误“底层连接已关闭:预期保持活动状态的连接已被服务器关闭”。

我使用 .Net 4.5 WCF 服务,我的应用程序连接到外部第 3 方 SOAP-WSDL 服务来执行操作。对该服务的大多数调用均已成功完成,但有一个特定的调用,其中 5% 的调用因该错误而失败

The underlying connection was closed: A connection that was expected to be kept alive was closed by the server

下面是该服务的绑定配置

<bindings>
      <customBinding>
        <binding name="AnotherServiceSoap12Binding" openTimeout="01:30" receiveTimeout="01:30" sendTimeout="01:30" closeTimeout="01:30">
          <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Soap12" writeEncoding="utf-8">
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="999999" />
          </textMessageEncoding>
          <httpTransport manualAddressing="false" 
            allowCookies="false" authenticationScheme="Anonymous" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" keepAliveEnabled="true" 

                maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" 
            proxyAuthenticationScheme="Anonymous" realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false" useDefaultWebProxy="true" />
        </binding>
      </customBinding>
    </bindings>

我还从日志中注意到连接没有超时,大约不到 10 秒就会出现该错误。

知道问题是什么,或者我如何获得更多数据来检测问题的根本原因。我还需要知道修复应该来自我的客户端应用程序还是来自第 3 方服务。

.net wcf soap wsdl wcf-binding
1个回答
0
投票

您应该检查您的客户端端点绑定

openTimeout="01:30" receiveTimeout="01:30" sendTimeout="01:30" closeTimeout="01:30"
的客户端配置是否与您的第3方服务相同,以及您的传输需求是否满足双方所需的要求。

<httpTransport manualAddressing="false" allowCookies="false" authenticationScheme="Anonymous" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" keepAliveEnabled="true" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"            proxyAuthenticationScheme="Anonymous" realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false" useDefaultWebProxy="true" />

当客户端超时大于服务器超时时,会发生此错误。 为了避免此错误,应增加 receiveTimeout 和 sendTimeout。

© www.soinside.com 2019 - 2024. All rights reserved.