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?
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With