WCF服务超时或关闭?

时间:2013-12-22 23:26:03

标签: c# wcf networking

我最近注意到在我们的生产环境中记录了异常,WCF服务在从我的前端服务器到ib逻辑服务器的调用之间超时。两者都使用WCF进行通信。前端服务器正在记录以下异常:

间歇性地发生这种情况。这是什么原因?它与网络有关吗?

Timestamp: 23/12/2013 07:59:00.507895
Message: HandlingInstanceID: 58495715-f5d8-49a9-9c90-763a1718228b
An exception of type 'System.ServiceModel.CommunicationException' occurred and was caught.
------------------------------------------------------------------------------------------
12/23/2013 07:59:00
Type : System.ServiceModel.CommunicationException, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : An error occurred while receiving the HTTP response to https://myservername:2083/IBServer/PayeesService.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
Source : Facade
Help link : 
Data : System.Collections.ListDictionaryInternal
TargetSite : System.Collections.Generic.List`1[Facade.BusinessObjects.Payee] GetPayeeList()
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.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at IB.Facade.PayeeFacade.GetPayeeList() in Facade.Payees.cs:line 236
   at LoginBase.RetrievePayees()
   at LoginBase.LoadPayees()
   at Login.LoadDefaultCache()

FRONTEND WCF绑定到Transaction Server上的WCF服务:

 <binding name="WSHttpBinding_ManagePayeeService" closeTimeout="00:02:00" openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:02:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">

            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />

            <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />

            <security mode="Transport">

                <transport clientCredentialType="None" proxyCredentialType="None" realm="" />

                <message clientCredentialType="UserName" algorithmSuite="Default" />

            </security>

        </binding>

交易服务器上的WCF BIN:

 <binding name="WSHttpBinding_ManagePayeeService" closeTimeout="00:02:00" openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:02:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
      <security mode="Transport">
        <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
        <message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="true" />
      </security>
    </binding>

3 个答案:

答案 0 :(得分:2)

您是否尝试过查看svclogs以获取有关出错的更多信息?

可以在system.diagnostics元素下的Web.config中配置此日志记录。以下内容取自我偶尔使用的一个测试文件。

注意:请勿在生产站点上始终保留此日志记录,因为日志会迅速增长到有问题的大小。因此,每当我将以下部分付诸实践时,我都会尽快将其评论出来。

启用此类日志记录时,如果同时捕获客户端和服务器日志,则效果最佳。通常,服务器日志将包含未传递到客户端的信息,反之亦然。

<system.diagnostics>
  <!--
    Trace Levels:
      Off, Critical, Error, Warning, Information, Verbose, ActivityTracing, All
  -->
  <!--<trace autoflush="true" />-->
  <sources>
    <source name="System.ServiceModel" switchValue="All" propagateActivity="true">
      <listeners>
        <add name="System.ServiceModel" type="System.Diagnostics.XmlWriterTraceListener" initializeData ="C:\Logs\MyWebsiteLogs\SVC\System.ServiceModel.svclog" />
      </listeners>
    </source>
    <source name="System.ServiceModel.MessageLogging" switchValue="All">
      <listeners>
        <add name="System.ServiceModel.MessageLogging" type="System.Diagnostics.XmlWriterTraceListener" initializeData ="C:\Logs\MyWebsiteLogs\SVC\WCF\System.ServiceModel.MessageLogging.svclog" />
      </listeners>
    </source>
    <source name="System.ServiceModel.IdentityModel" switchValue="All">
      <listeners>
        <add name="System.ServiceModel.IdentityModel" type="System.Diagnostics.XmlWriterTraceListener" initializeData ="C:\Logs\MyWebsiteLogs\SVC\WCF\System.ServiceModel.IdentityModel.svclog" />
      </listeners>
    </source>
    <source name="System.ServiceModel.Activation" switchValue="All">
      <listeners>
        <add name="System.ServiceModel.Activation" type="System.Diagnostics.XmlWriterTraceListener" initializeData ="C:\Logs\MyWebsiteLogs\SVC\WCF\System.ServiceModel.Activation.svclog" />
      </listeners>
    </source>
    <source name="System.ServiceModel.Serialization" switchValue="All">
      <listeners>
        <add name="System.ServiceModel.Serialization" type="System.Diagnostics.XmlWriterTraceListener" initializeData ="C:\Logs\MyWebsiteLogs\SVC\WCF\System.ServiceModel.Serialization.svclog" />
      </listeners>
    </source>
    <source name="System.IO.Log" switchValue="All">
      <listeners>
        <add name="System.IO.Log" type="System.Diagnostics.XmlWriterTraceListener" initializeData ="C:\Logs\MyWebsiteLogs\SVC\WCF\System.IO.Log.svclog" />
      </listeners>
    </source>
    <source name="Cardspace" switchValue="All">
      <listeners>
        <add name="Cardspace" type="System.Diagnostics.XmlWriterTraceListener" initializeData ="C:\Logs\MyWebsiteLogs\SVC\WCF\Cardspace.svclog" />
      </listeners>
    </source>
  </sources>
</system.diagnostics>

您可以使用Service Trace Viewer Tool查看日志。此工具可能已经安装,也可能没有与当前版本的Visual Studio / .NET Framework一起安装。

编辑:对于上下文,我发现每当我在WCF中遇到这样的通信异常时,总是在服务器上变成某种类型的序列化错误。然而,根据我的经验,不确定其他场景可能会产生这样的错误。

答案 1 :(得分:1)

我通常在没有处理异常时得到这个。事件日志中是否显示任何内容?您使用IIS还是自托管?

答案 2 :(得分:0)

看看MaxRequestLength和readerQuotas,看起来有时默认设置不够