tags:

views:

898

answers:

2

I've made soap connection to a server and the server doesn't seem to be dropping that connection, in netstat the status of the connection is listed as CLOSE WAIT.

I'm told that the client that created the soap connection has to send a command to the server to close the connection. Can anyone tell me the correct way to do this in C#? Below is an example piece of code.

SOAPServer.Service Soap = new SOAPServer.Service(); // SOAPServer is a web reference
Soap.Timeout = 30000;
string[] SOAPReturnResult = Soap.DepotData(100, "Test");
Soap.Dispose();

Thanks

A: 

Wrap it in a using block.

using (SOAPServer.Service Soap = new SOAPServer.Service())
{
Soap.Timeout = 30000;
string[] SOAPReturnResult = Soap.DepotData(100, "Test");
}

Note that this only marks the connection as closed. It might still show up as open via netstat even for a little time after the connection has been closed.

Chris Ballance
How is your using block any different to calling Dispose() manually as in the question ?
andynormancx
If this line throws an exception, you may never call dispose:string[] SOAPReturnResult = Soap.DepotData(100, "Test");
Chris Ballance
A: 

CLOSE WAIT state means that the server received a TCP-FIN from your client (i.e. a passive close), the server has to close its socket (send TCP-FIN to the client) in order to get the server socket out of CLOSE WAIT state. So this may not necessary be a problem on the client side but on the server side where the server socket does not get closed correctly.

What does it look like on the client side? FIN-WAIT-1 or FIN-WAIT-2 could indicate this may be the issue.

Fredrik Jansson
This seems to make sense from the tests we've done on the server and client. (I make a call to the server and can see that the server stays in CLOSE_WAIT while the client stays in FIN_WAIT_2) But how do you close the socket on the server end programatically?
Jack Mills
If you can reach the socket, you should be able to just close it. Is the server also .Net or something else?
Fredrik Jansson
To catch it; the server will probably get an exception or an EOF when reading the socket, that could be one way. Not sure if you can register an event to be called when the other side closes "its side of the socket".
Fredrik Jansson