How to Check the State of Channel in WCF Proxy Client

- J.D. Meier, Carlos Farre, Jason Taylor, Prashant Bansode, Steve Gregersen, Madhu Sundararajan, Rob Boucher

You can check the state of channel during proxy invocation by checking the value or proxy.state. You avoid this way throwing exception on the proxy, due to channel being closed due to an unhandled exception on service.
try
{

    ServiceClient proxy = new ServiceClient();
    proxy.ClientCredentials.UserName.UserName = "user";
    proxy.ClientCredentials.UserName.Password = "password";
    proxy.GetData(2);
    if (proxy.State = CommunicationState.Opened)
    {
        proxy.GetData("data");
    }
    proxy.Close();
}
catch (FaultException ex)
{
    
}

Last edited Jun 13, 2008 at 6:40 PM by prashantbansode, version 1

Comments

No comments yet.