2012-08-07 167 views
1

我正在使用.NET 4.0創建一個WCF Web服務,該服務託管在IIS 7.0上。一切似乎都很好,除了一個奇怪的WCF例外如下。奇怪的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任何想法...!

+2

WCF調試從來沒有樂趣。我建議通過閱讀[緩解WCF調試的痛苦](http://davybrion.com/blog/2008/08/easing-the-pain-of-wcf-debugging/),這會教會你avout'。 svclog'文件和服務跟蹤查看器工具。 – AakashM 2012-08-07 08:01:17

+0

您可以將您的服務/端點元素髮布到配置中嗎?以及您使用哪種綁定會有所幫助。 – Rajesh 2012-08-07 08:35:51

+0

您的服務代碼中可能存在未處理的異常?這是您在這種情況下會看到的錯誤。 – InSane 2012-08-07 09:03:22

回答

0

連接僅在請求級別關閉。所以這個服務甚至沒有被調用。

  1. 嘗試在客戶端級別增加closeTimeout的值。
  2. 使用client.Close();在使用後關閉每個實例的客戶端連接。
  3. 檢查服務的uri是否正確。
相關問題