繁体   English   中英

WCF 客户端关闭连接后连接状态CLOSE_WAIT

[英]WCF connection status CLOSE_WAIT after client close connection

我的服务器连接有很大问题。 我有一个应用程序,它使用来自客户的数据,与他们一起做很多事情,最后返回确认。 客户端与服务器握手、传输数据、等待返回时是一个WCF服务。

不幸的是,客户已将超时设置为 10 分钟,这还不够,因为如果环境收费,处理会花费更多时间。 在那之后,客户端抛出 SocketTimeoutException 并向我的服务器发送关闭连接的请求,但如果服务器开始工作,他无法中断并关闭连接,因此服务器端的连接处于 CLOSE_WAIT 状态。

你知道吗,如何在 c# 中捕获此连接的状态? 感谢我可以停止服务器作业并关闭连接。

这是我的服务的定义:

[ServiceContractAttribute(Namespace = "Services.Interfaces.ISaver", ConfigurationName = "ISaverPort")]
    public interface ISaverPort
    {
        [System.ServiceModel.OperationContractAttribute(Action = "Services.Interfaces.ISaver.SaveData")]
        [System.ServiceModel.XmlSerializerFormatAttribute()]
        object SaveData(object request);

        [System.ServiceModel.OperationContractAttribute(Action = "Services.Interfaces.ISaver.GetData")]
        [System.ServiceModel.XmlSerializerFormatAttribute()]
        object GetData(object request);
    }

我试图通过检查OperationContext.Current.Channel.State来捕获连接 state 。 但它始终处于“已打开”状态。

我也尝试过处理事件,但它从未进入方法“HandleEvent”。

            OperationContext.Current.Channel.Faulted += new EventHandler(HandleEvent);
            OperationContext.Current.Channel.Closed += new EventHandler(HandleEvent);
            OperationContext.Current.Channel.Closing += new EventHandler(HandleEvent);
            OperationContext.Current.Channel.Opening += new EventHandler(HandleEvent);
            OperationContext.Current.Channel.Opened += new EventHandler(HandleEvent); 

当然,我设置了绑定超时设置,但它什么也没做。

<wsHttpBinding>
        <binding name="SaverBinding" closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00" receiveTimeout="00:10:00" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
          <security mode="Message">
            <message clientCredentialType="UserName"/>
          </security>
        </binding>
      </wsHttpBinding>

我希望有人能帮助我,谢谢:)

据我所知,大多数情况下你是抓不到这个连接的state的。 知道客户端和服务器连接在一段时间内是否仍然存在的方法是发送消息进行测试。

在您的情况下,请尝试从客户端发送消息以检查连接是否存在。 然后修改客户端最大超时时间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM