2012-08-07 135 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是否正确。
相关问题