简体   繁体   中英

WCF connection status CLOSE_WAIT after client close connection

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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