Yoann. B
Yoann. B

Reputation: 11143

Keep WCF Service Connected

How can I keep my WCF Service Client Connected with WinForm even if a Faulted State appened ?

Thanks.

Upvotes: 1

Views: 2220

Answers (2)

Yoann. B
Yoann. B

Reputation: 11143

Answer myself :)

You might subscribe to InnerChannel Events

            svc.InnerChannel.Closed += InnerChannel_Error;
            svc.InnerChannel.Closing += InnerChannel_Error;
            svc.InnerChannel.Faulted += InnerChannel_Error;

Then Handle Exceptions and Recreate the Service Proxy

private void InnerChannel_Error(object sender, EventArgs e)
{
    var svc = _entrepotService as EntrepotServiceProxy;
    try
    {
        if (svc != null)
        {
            if (svc.State != CommunicationState.Faulted)
            {
                svc.Close();
            }
            else
            {
                svc.Abort();
            }
        }
    }
    catch (CommunicationException)
    {
        if (svc != null) svc.Abort();
    }
    catch (TimeoutException)
    {
        if (svc != null) svc.Abort();
    }
    catch
    {
        if (svc != null) svc.Abort();
        throw;
    }
    _entrepotService = new EntrepotServiceProxy();
}

Upvotes: 3

Marc Gravell
Marc Gravell

Reputation: 1062780

As far as I know, a faulted state is usually terminal to a WCF proxy. So no, I don't think so.

Upvotes: 2

Related Questions