gpt4 book ai didi

c# - WCF 超时太快 & 'Connection was closed unexpectedly' 异常

转载 作者:太空狗 更新时间:2023-10-29 17:51:57 26 4
gpt4 key购买 nike

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

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

异常(exception):

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)

内部异常:

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)

据我所知,绑定(bind)设置正确且超时超过 120 秒。这是客户端绑定(bind):

<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>

这是服务器绑定(bind):

<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>

这是相关方法的接口(interface):

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

最佳答案

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

来自微软文档:
由于以下原因,连接可以被视为不活动:

  • HTTP.sys Timer_ConnectionIdle 计时器已过期。连接已过期并保持闲置状态。
  • HTTP.sys Timer_EntityBody 计时器已过期。连接已过期在请求实体主体到达之前。当很明显请求有一个实体主体,HTTP API 打开Timer_EntityBody 定时器。最初,此计时器的限制设置为连接超时值。每次另一个数据指示是收到此请求后,HTTP API 会重置计时器以提供connectionTimeout 中指定的连接更多分钟属性。
  • HTTP.sys Timer_AppPool 计时器已过期。连接已过期因为请求在应用程序池队列中等待太久服务器应用程序出列并处理它。本次超时时间是连接超时。

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

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

祝你好运。

关于c# - WCF 超时太快 & 'Connection was closed unexpectedly' 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22507779/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com