0

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?

lysergic-acid
  • 19,570
  • 21
  • 109
  • 218

1 Answers1

0

The "problem" is that the method is oneway. At some degree, this is a fire and forget (put sessions aside) operation and if it throws an exception- the client has no way of knowing that. From the clients perspective, the request is successful as soon as it is received on the other side (received not processed).

I advise you to try the same with non one way first.

Also, please post the code that you used to subscribe to the faulted event. What hosting are you using? how are you creating the proxy? (ChannelFactory?)

You can try to subscribe on the Faulted event of the ServiceHost (if you have one) and see whether this fires.

Also, did you try querying the proxy for its state?

Also, please refer to this question on SO, I believe you may get your answer there.

Cheers

Community
  • 1
  • 1
Vitaliy
  • 8,044
  • 7
  • 38
  • 66
  • Updated my question with how i setup the client + event hooking. I also tried querying the proxy's state, it always returned Opened. – lysergic-acid Aug 14 '12 at 18:35
  • Looks OK. Did you try subscribing to the ServiceHost.Faulted? Also, did you try it w/o one-way? – Vitaliy Aug 14 '12 at 18:49