tags:

views:

68

answers:

2

Do CommunicationExceptions and/or TimeoutExceptions need to be handled in the Service Implementation? (in addition to the client?). What happens when a client times out ? Does the service continue processing the message, or does an exception get thrown?

Thanks

-Vic

For example do, I need to do the following ??

public MyServiceImpl:IMyService
{

 void DoSomething()
  {
  try{
   //Do something
  }
  catch (Communication exception){}
  catch (Timeout exception){}
  }
 }
}
+1  A: 

Since you're not in a callback scenario, your service method won't even be called if there's a timeout (since it will be catched by the various dispatchers that get the message before your method does). So no need to catch these exceptions here.

If you're using a Stream as one of the parameters of your operation, things are a little different though, since you're likely to run into an exception while reading the stream if your client throws a hissy fit. But in that case you'd have to guard for exceptions anyway.

Yann Schwartz
A: 

As per usual: it depends :-)

If you have per-call instancing, or one-way messages, then even if a bad thing (an exception) happens on the server, they'll be propagated to the client (or in one-way scenarios: just dropped), and you don't have to worry about them all that much.

HOWEVER: if you have a session scenario, where either your transport protocol (TCP/IP in the case of netTtcp binding) uses a transport session, or where your e.g. wsHttpBinding establishes an application session with the server, then you need to make absolutely sure on the server to catch all exceptions and handle them and return them only as SOAP faults.

If you don't, then the channel (the communication pipe between your client's proxy instance and the server instance) will be "faulted", e.g. unusable and the client proxy instance will need to be recreated.

Also, keep in mind that .NET exceptions are just that - a .NET specific thing. If your service will need to be interoperable and be called from e.g. Java, Ruby, PHP or other clients, you absolutely MUST catch all .NET exceptions on the server side and turn them into SOAP faults (which are the interoperable equivalent). You can do this by implementing the IErrorHandler interface on your server side.

Marc

marc_s