Check WCF Connection

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

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

Then I have a link to ICommunicationObject

The WCF service may not work when you connect or close later. What is the correct way to test the WCF service. One direct way is to use the CommunicationException mechanism. But what about the ICommunicationObject.State property? Should I check in a failed state before calling the WCF method? What is the practice?

+7
wcf
source share
1 answer

There is no magic way to check if the WCF service is running, other than calling and being prepared to handle exceptions that occur if they are not running.

ICommunicationObject.State will inform you that the channel between the client and the server is “faulty” if the previous operation resulted in an error and this error was not properly processed on the server (and thus the channel was “faulty”, for example, useless).

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

But then: what is the real use of the first call to MyService.Ping() and the need to handle possible exceptions if the service is not alive and then calls your actual method, and not just calls MyService.MyMethod() and handles any relevant exceptions?

+13
source share

All Articles