I am learning WCF and trying out different examples from things learned in the book.
I have a simple service setup as follows:
[ServiceContract]
interface MyService
{
[OperationContract(IsOneWay = true)]
void Throws();
}
My client code is using the ChannelFactory class to create a proxy:
var baseTcpAddress = new Uri("net.tcp://localhost/hello");
var tcpBinding = new NetTcpBinding();
// Create client channel.
ChannelFactory<ITestService> factory = new ChannelFactory<ITestService>(tcpBinding, new EndpointAddress(baseTcpAddress));
var channel = factory.CreateChannel();
var commObject = channel as ICommunicationObject;
commObject.Faulted += commObject_Faulted;
commObject.Closed += commObject_Closed;
When this method is called it throws an unhandled exception (not derived from FaultException), and a subsequent call using the same proxy throws an exception and the channel gets faulted.
The issue is i am registered on the Faulted event of the proxy channel, but i am not getting any notification, only when attempting to access the proxy.
My question is -- how can a client protect itself from a faulting proxy? shouldn't the proxy inform the client that it's not usable instead of letting the client try and use it?