2014-03-19 46 views
9

当调用返回字符串“success”的方法时,WCF客户端在120秒后返回上述异常。来自服务器的日志显示它完全执行并在大约3分钟内完成。启用跟踪后,我看不到任何错误。 任何帮助将不胜感激由于类似问题的其他建议不幸没有帮助。谢谢!WCF超时太快&'连接意外关闭'异常

编辑 - 解决:原来,客户端正在使用Smoothwall过滤设备,两分钟后关闭连接。

例外:

System.ServiceModel.CommunicationException The underlying connection was closed: The connection was closed unexpectedly. 
Stack Trace: at System.Net.HttpWebRequest.GetResponse() 
    at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) 

的InnerException:

System.Net.WebException The underlying connection was closed: The connection was closed unexpectedly.The underlying connection was closed: The connection was closed unexpectedly. 
Stack Trace: at System.Net.HttpWebRequest.GetResponse() 
    at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) 

据我所看到的,绑定正确设置和超时超出120秒。这里的客户端绑定:

<bindings> 
    <customBinding> 
     <binding name="CustomBinding_IPHG" closeTimeout="00:05:00" 
      openTimeout="00:05:00" receiveTimeout="00:15:00" sendTimeout="00:15:00"> 
      <security authenticationMode="SecureConversation" requireDerivedKeys="false"> 
       <localClientSettings maxClockSkew="00:30:00" /> 
       <localServiceSettings maxClockSkew="00:30:00" /> 
       <secureConversationBootstrap authenticationMode="UserNameOverTransport"> 
        <localClientSettings maxClockSkew="00:30:00" /> 
        <localServiceSettings maxClockSkew="00:30:00" /> 
       </secureConversationBootstrap> 
      </security> 
      <textMessageEncoding> 
       <readerQuotas maxStringContentLength="5242880" /> 
      </textMessageEncoding> 
      <httpsTransport maxReceivedMessageSize="6553600" useDefaultWebProxy="true" /> 
     </binding> 
    </customBinding> 
</bindings> 
<behaviors> 
<endpointBehaviors> 
<behavior name="commonBehaviour"> 
    <dataContractSerializer maxItemsInObjectGraph="2147483647"/> 
    <clientCredentials> 
    <serviceCertificate> 
     <authentication certificateValidationMode="PeerOrChainTrust"/> 
    </serviceCertificate> 
    </clientCredentials> 
</behavior> 
</endpointBehaviors> 
</behaviors> 

这里的服务器绑定:

<bindings> 
    <customBinding> 
    <binding name="CommonBinding" closeTimeout="00:05:00" openTimeout="00:05:00" receiveTimeout="00:15:00" sendTimeout="00:15:00"> 
     <transactionFlow /> 
     <security authenticationMode="SecureConversation" requireDerivedKeys="false"> 
     <secureConversationBootstrap authenticationMode="UserNameOverTransport"> 
      <localServiceSettings maxClockSkew="00:30:00" /> 
      <localClientSettings maxClockSkew="00:30:00" /> 
     </secureConversationBootstrap> 
     <localServiceSettings maxClockSkew="00:30:00" /> 
     <localClientSettings maxClockSkew="00:30:00" /> 
     </security> 
     <textMessageEncoding> 
     <readerQuotas maxStringContentLength="41943040"/> 
     </textMessageEncoding> 
     <httpsTransport maxBufferSize="41943040" maxReceivedMessageSize="41943040" /> 
    </binding> 
    </customBinding> 
</bindings> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="BehaviorRBS"> 
     <serviceMetadata httpsGetEnabled="true" httpGetEnabled="false" /> 
     <serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="false" /> 
     <dataContractSerializer maxItemsInObjectGraph="2147483647" /> 
     <serviceCredentials> 
     <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="PHGAPI.PHGUserNamePassValidator, PHGAPI"/> 
     <serviceCertificate 
       findValue="*.domainname.com" 
       x509FindType="FindBySubjectName" 
       storeLocation="LocalMachine" 
       storeName="My" /> 
     </serviceCredentials> 
     <serviceThrottling maxConcurrentCalls="200" maxConcurrentSessions="400" maxConcurrentInstances="600" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
<services> 
    <service behaviorConfiguration="BehaviorRBS" name="PHGAPI.iAPI"> 
     <endpoint address="" binding="customBinding" bindingConfiguration="CommonBinding" contract="PHGAPI.IiAPI" /> 
    </service> 
</services> 

这是有问题的方法接口:

[OperationContract] 
string SetSuspensions(List<Suspension> suspensions); 
+0

看起来它被编辑了出来,但是我读到了,你说服务器完成了它的执行?这个错误很可能从服务器抛出,而不是超时。要清楚的是,它的客户端对服务器错误的响应。 – paqogomez

+0

也许会导致序列化问题? – lavrik

+0

@paqogomez我写了一个日志文件在服务器上,并且在'return'成功之前立即写入日志';'线。该日志条目在大约3分钟后发生,大约在客户端收到异常后大约一分钟。正因为如此,我相信服务器运行良好。 – Marcus

回答

2

跟踪这些问题可以是一个痛苦。尝试以下方法来帮助追踪问题。

1)确定问题出在哪里,即客户端或服务器。在IDE中以调试模式启动服务,然后使用WCF Test client而不是您自己的客户端来排除客户端配置问题。

2)安装并使用Fiddler2检查来自服务的HTTP消息。您会看到服务是否有回应,以及内容是什么。 3)假设这是一个同步调用,保持一个线程打开三分钟对于性能无论如何是不利的。也许考虑重构服务,以便更快地返回数据或使其成为async

+0

1)提琴手只适用于客户端堆栈。 2)即使客户端异步完成连接仍可能超时 – iamkrillin

-3

建议您在业务逻辑方法中使用事务范围。

如果您遇到这种错误,请停止您的数据库服务器并重新启动。我认为这可能会解决你的问题。因为有时候数据库流量拥塞会比开发者预期的花费更多的时间。因此,如果您的应用程序很繁重,请将从应用程序到服务器的更少数据库调用。

4

我会研究WCF和默认值为120秒的相关配置设置。为此,您可能需要查看HTTP.sysconnectionTimeout的值。

从微软文档:
连接可以被视为无效,原因如下:

  • 是Http.sys Timer_ConnectionIdle计时器到期。连接 过期并保持空闲状态。
  • HTTP.sys Timer_EntityBody定时器已过期。在请求实体正文到达之前,连接已经过期 。当清楚 请求具有实体主体时,HTTP API将打开Timer_EntityBody计时器。最初,此计时器的限制设置为 connectionTimeout值。每次在此请求上接收到另一个数据指示 时,HTTP API都会重置定时器,以使连接更多分钟,如connectionTimeout 属性中指定的那样。
  • HTTP.sys Timer_AppPool计时器已过期。连接已过期 ,因为请求在应用程序池队列中等待 服务器应用程序的出列和处理时间过长。这个超时时间 是connectionTimeout。

默认值是00:02:00(两分钟)。

http://www.iis.net/configreference/system.applicationhost/sites/sitedefaults/limits

好运。

+0

不幸的是,这并没有工作,虽然我真的很希望它会。 IIS站点被调整为900秒连接超时,但120秒后客户端发生相同的超时。客户端(控制台应用程序)是否有类似的超时? – Marcus

+0

以下可能会有所帮助,因为该操作似乎有类似的问题:http://stackoverflow.com/questions/14266854/what-130-second-timeout-is-killig-my-wcf-streaming-service-call – Seymour

+0

位于C:\ Windows \ System32 \ LogFiles \ HTTPERR \ httperr1.log的日志文件可能会提供有关超时原因的一些信息。 – Seymour

2

根据您提出的问题和下面的评论中发布的信息,听起来像是在这个等式的客户端部分超时。由于生成的客户端上的默认超时时间非常短。只需让你的客户端修改他们的配置来增加超时。

--exert(客户端配置) -

<configuration> 
    <startup> 
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> 
    </startup> 
    <system.serviceModel> 
     <bindings> 
      <basicHttpBinding> 
       <binding name="BasicHttpBinding_IService1" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" /> 
      </basicHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/" 
       binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1" 
       contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" /> 
     </client> 
    </system.serviceModel> 
</configuration> 

您正在使用的绑定是不同的,但所有绑定具有这些特性。我通常增加所有的超时时间,但对你来说最重要的是“receiveTimeout”

+0

谢谢,我认为这是一个客户端问题太。客户端绑定已经有15分钟的超时时间 - 这在原始文章中列出。我已经要求客户仔细检查任何网页过滤器,以防造成此问题。 – Marcus

2

客户位于何处? (同一公司网络,同一国家)

客户端的网络速度是多少?

参数列表暂停的大小是多少字节?

您是否尝试使用Fiddler或其他网络软件包捕获传输?

在之前的工作中,出现了服务器中的每个错误都记录到不同服务器的情况;问题是具有10,000行错误行的传入消息被发送到日志,但不是作为单个失败错误发送,而是作为相同错误的10,000倍发送。

序列化这个巨大的200MB +对象被发送到另一台服务器导致内部网络被视为100%被利用并使服务器变为100%,因此IIS无法及时响应任何其他请求。

我不是说这可能是你的情况,我只是分享一个超时情况,我有问题不在超时的方法中,但在服务的另一个组件中。

+0

你会建议在客户端还是服务器端使用Fiddler? – Marcus

+0

你有权访问双方吗?如果问题出在单个客户端上,那么在客户端上。如果有多个客户端,则检查服务器中的流量 – berXpert

相关问题