Posted by: Mark Wilkinson | July 8, 2009

First post

Something I’ve come across using WCF.

A co-worker said he was getting exceptions when a network connection was dropped, and his proxy client state would drop (thus throwing an exception).

My solution that I’ve been using when trying to invoke any WCF client method is to do the following, thus preventing an exception from occuring:

if (client != null && client.State == CommunicationState.Opened)
{
    client.Method();
}
else
    this.ConnectToWCFHost();

If it’s null, try reconnecting and instantiating the client instance.  You might want to count the number of attempts to connect and then notify the system (through an event viewer for instance) that the connection cannot be established.


Responses

  1. Is there or can you build connection pools?

  2. On the host side (the service side), I keep a Generic list of connected clients, or callback channels. That is managed and updated when a client drops as well. Maybe this is similar to what you’re suggesting.

    The call/code above is on the client/caller side of the WCF service.

    also, some people don’t like to use the variable name client for the instance context, a lot use proxy as that might make more sense.


Leave a response

Your response:

Categories