Link to home
Start Free TrialLog in
Avatar of parabellum
parabellum

asked on

WCF, How to capture the client disconnection at the server side.


Hello,

I  have written a file server/client using WCF (net.tcp) .  Here is my problem:

While a client is uploading a file to the server, when I pull the ethernet cable at the client side my client gets an exception.(Which is obvious since i have disconnected the client from server).

 Below is the Upload file function. The problem is i  am not getting any exception  at the server side at all. So i can not detect that there is a problem with the client side.

How can i understand that the file transfer is not complete ?

 


public string UploadToServer(Stream stream)
{
  FileStream fStream=File.Open(.....);

 try
{
  while(stream.Read(fileUploadBuffer,0,bufferLen)>0)
   fStream.Write(fileUploadBuffer,0,....)

  return "OK";
}
 catch (Exception ex)
{
  // Log operations here.
  return "ERROR";
}


}

Open in new window

Avatar of Dennis Aries
Dennis Aries
Flag of Netherlands image

Did you set a read-timeout? If so, you will have a difference between an EOF or a read-timeout. The latter meaning that the connection has been broken, ghe former meaning that you have reached the end of the file and that the stream can be closed.
Avatar of parabellum
parabellum

ASKER


Well the problem is my input(Stream stream) does not support Read timeout.(Its CanTimeout property is false). And my FileSTream fStream object does not support Timeout too.  So i can not get any timeout at the server side.
ASKER CERTIFIED SOLUTION
Avatar of Dennis Aries
Dennis Aries
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

Currently the server does not throw any exceptions and other clients can upload to the server.(Server CPU usage does not go peak when a client is forced to disconnect.)

 I do not know the inner working details of WCF maybe it is suspending the operation internally. I am not sure about that.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial