tags:

views:

149

answers:

1

Hi

I have a WCF service and client. I connect to WCF via

ChannelFactoryBase<(Of <(TChannel>)>)..::.CreateChannel Method

Then I have a reference to ICommunicationObject

WCF service may be not working when connecting or closed later. What is correct way to check if WCF service is working. One direct way is to use CommunicationException mechanism. But what about ICommunicationObject.State property? Should I check if it is in faulted state before any WCF method call? What is best practise?

+2  A: 

There's no magic way to check whether a WCF service is working - other than calling it and being prepared to handle exceptions that arise if it's not working.

ICommunicationObject.State will only tell you that a channel between the client and the server is "faulted", if a previous operation resulted in an error and that error wasn't properly handled on the server (and thus the channel was "faulted", e.g. rendered useless).

You could - if you control both ends of the wire - include a "dummy" ping method (or something like returning the version number of the service) to be able to first call something like that, so just see if the communication channel is still alive.

But then: what's the real benefit of first calling MyService.Ping() and having to handle possible exceptions if the service isn't alive, and then calling your actual method, instead of just calling MyService.MyMethod() and handle any relevant exceptions?

marc_s
Thanks,I wonder why there is ICommunicationObject.Faulted eventand ICommunicationObject.State property for? If i could use them somehow
Captain Comic
The "Faulted" event can be handled to be notified right away about a channel being faulted, e.g. you could then re-create the proxy, for instance. The State has more than just the "Faulted" state, but it doesn't offer any hint whether the service is "alive" or not.
marc_s