2
votes

I'm learning about FaultException and CLR Exceptions in the context of WCF services but something is not clear. In the book "Learning WCF" it says that when a service throws a normal CLR Exception it's caught by the service model, the service model constructs a SOAP message from that, sends it back to the client, and the exception is thrown at the client again. There the channel is faulted.

So I've built a service which throws a NullReferenceException. A client calls the service, catches the exception and print the CommunicationState.

try
{
    x = Proxy.Call(); // throws NullReferenceException at the service
}
catch (Exception ex) // or CommunicationException is the same
{
    MessageBox.Show("" + Proxy.InnerChannel.State);
}

But the State member stays on Opened and I can call the service forever....

What is correct here? Should a client go into faulted state when a service throws a CLR exception and stays in Opened state when a service throws a FaultException? Or does it always stay open?

2

2 Answers

2
votes

I can not find official confirmation, but here is what going on in my opinion:

You using BasicHttpBinding which does not keep connection open, but creates new one on every request. If you switch to NetTcpBinding, you will see expected behavior(just tested locally)

1
votes

When error occures session's state gets in fault state and since binding such as basicHttpBinding does not support session at all you cannot distincly see that connection is in faulted state. Try to make use of binding which supports session such as netTcpBinding and you should discover that session, after exception being thrown, is not accessible.