views:

25

answers:

1

Hi All,

I have a wcf service hosted in iis. The endpoint uses wsHttpBinding.

I have a lot of clients that are using the service.
The internet connection is unstable. The clients uses the service to insert data in db.

What is the best practice of exception handling in the client.
Is it good choise to use the using statemen and initialize new connection every time the client needs to insert data (call the service) or should keep opened reference and reinitialize every time it detects no connection ?

I do not like when the client calls the service to show an error to the user telling to retry again. Can it retry automatically?

Regards

+1  A: 

First don't use using when dealing with WCF proxy or channel. Use this approach to close proxy or channel. Usage of proxy is dependent on your application, your requirements and your current configuration.

WsHttpBinding by default uses message security with Windows authentication and with establishing security context. This means that at the beginning of communication user is authenticated and security context is created. Security context is similar to security session so the user doesn't have to be authenticated in subsequent calls from the same proxy. Usage of security context is only valuable if you plan to use proxy for several calls otherwise it is overhead. But creating security context also has side effect - single service instance handles all calls from that proxy. Life time of the service is controlled by several timeouts. Most important is receive timeout with default value 10 minutes. If no request from the proxy arrives within 10 minutes instance is released and channel is closed but proxy doesn't know about it. Next time you will use the proxy it will fire exception. Channel is also closed by any undhandled exception during request processing on service. So if you want to reuse proxy you have to deal with additional complexity of checking channel state and recreating proxy if something goes wrong.

Ladislav Mrnka
Probably you are missing a link in the text ("Use this [approach][1]") ?
darko petreski
Sorry, I have added link.
Ladislav Mrnka