奇怪的WCF异常:底层连接已关闭:连接意外关闭

时间:2012-08-07 07:01:53

标签: .net wcf wcf-binding

我正在使用.NET 4.0创建一个托管在IIS 7.0上的WCF Web服务。除了如下的奇怪的WCF异常外,一切似乎都很好。

    Message       : The underlying connection was closed: The connection was closed unexpectedly.
Stack Trace   : Server stack trace: 
   at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

从第一眼看,我认为,它应该是与消息大小相关的一些事情,因此我调整了我的绑定配置:

<binding 
    closeTimeout="00:01:00"
    openTimeout="00:01:00"
    receiveTimeout="00:10:00"
    sendTimeout="00:01:00"
    allowCookies="false"
    bypassProxyOnLocal="false" 
    hostNameComparisonMode="StrongWildcard" 
    maxBufferSize="2147483647" 
    maxBufferPoolSize="2147483647"
    maxReceivedMessageSize="2147483647"
    messageEncoding="Text"
    textEncoding="utf-8"
    transferMode="Buffered"
    useDefaultWebProxy="true">
          <readerQuotas
        maxDepth="2147483647"
        maxStringContentLength="2147483647"
        maxArrayLength="2147483647"
        maxBytesPerRead="2147483647"
        maxNameTableCharCount="2147483647" />
          <security mode="Transport">
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>

<serviceBehaviors>
    <behavior>
            <serviceMetadata httpGetEnabled="false" />
            <serviceDebug includeExceptionDetailInFaults="true" />
            <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
        </behavior>
</serviceBehaviors>

不幸的是,它没有像我预期的那样工作。另一个想法来了,我认为它应该是与IIS配置相关的东西,所以我改变了我的web.config如下:

    <system.web>
    <compilation targetFramework="4.0" />
    <globalization culture="en-US" uiCulture="en-US" />
    <customErrors mode="RemoteOnly"></customErrors>
    <httpRuntime executionTimeout="10800" maxRequestLength="2147483647" />
  </system.web>

不幸的是,上述任何修改都无法解决我的问题。我仍然在客户端站点看到奇怪的WCF异常。以下是客户端绑定:

<binding name="myClientBinding"
             closeTimeout="00:10:00"
             openTimeout="00:10:00"
             receiveTimeout="01:00:00"
             sendTimeout="01:00:00"
             allowCookies="false"
             bypassProxyOnLocal="false"
             hostNameComparisonMode="StrongWildcard"
             maxBufferSize="2147483647"
             maxBufferPoolSize="524288"
             maxReceivedMessageSize="2147483647"
             messageEncoding="Text"
             textEncoding="utf-8"
             transferMode="Buffered"
             useDefaultWebProxy="true">
      <readerQuotas
        maxDepth="21474836"
        maxStringContentLength="21474836"
        maxArrayLength="21474836"
        maxBytesPerRead="21474836"
        maxNameTableCharCount="21474836" />
      <security mode="Transport">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>

有关WCF&amp; IIS ...!

1 个答案:

答案 0 :(得分:0)

连接仅在请求级别关闭。所以甚至没有调用该服务。

  1. 尝试在客户端级别增加closeTimeout的值。
  2. 使用client.Close();使用后关闭每个实例的客户端连接。
  3. 检查服务的uri是否正确。