【问题标题】:WCF connection status CLOSE_WAIT after client close connectionWCF connection status CLOSE_WAIT after client close connection
【发布时间】:2022-12-02 10:51:30
【问题描述】:

I have a big problem with connections to my server. I have a application which consuming data from clients, making many things with them and at the end returning confirmation. It is a WCF service when client making hand-shake with server, transfering data and waiting for return.

Unfortunately client have set timeout for 10 minutes and it's not enough, becouse processing taking more time if environment is charged. After that time client throwing SocketTimeoutException and sending to my server request to close the connection, but if server start the job he can't break this and close the connection so connection on the server side is in the CLOSE_WAIT status.

Do you know, how to catch this connection's status in c#? Thanks that I can stop server job and close the connection.

This is definiton of my service:

[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);
    }

I had tried to catch connection state by checking OperationContext.Current.Channel.State. But it's always in 'Opened' status.

Also I tried handle event but it's never enter to method '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); 

Of course I set binding timeout settings but it's not making anything.

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

I hope that anybody can help me, Thank you :)

【问题讨论】:

    标签: c# .net wcf .net-4.0 wcf-binding


    【解决方案1】:

    As far as I know, you can't capture the state of this connection in most cases. The way to know if the client and server connection is still in place over a period of time is to send a message to test.

    In your case, try sending a message from the client to check if the connection exists. Then modify the maximum client timeout.

    【讨论】:

      猜你喜欢
      • 2020-11-11
      • 2014-08-07
      • 1970-01-01
      • 2020-12-11
      • 2012-07-28
      • 2011-04-19
      • 2019-02-02
      • 1970-01-01
      • 2020-03-29
      相关资源
      最近更新 更多