1

我正在使用 .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 和 IIS 发生了什么的任何想法......!

4

1 回答 1

0

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

  1. 尝试在客户端级别增加 closeTimeout 的值。
  2. 使用 client.Close(); 使用后关闭每个实例的客户端连接。
  3. 检查服务的 uri 是否正确。
于 2013-09-05T09:17:37.550 回答