Alaa Masalmeh

Alaa Masalmeh

  • NA
  • 174
  • 852

How to Throw FaultException From Duplex RS MessageInspector

Aug 11 2014 4:38 AM
I have two Full Duplex Services and one Routing Service which forwards the request to one of the Full Duplex Services regarding to the caller ID and other considerations. this means if the callerId is X the request will be forwarding to first service. if the callerId is Y the request will be forwarding to the second service. if the callerId is Z the RoutingService should close the connection gracefully and throw FaultException to tell the client that he can't contact any service. I put the check code in MessageInspector at the AfterReceiveRequest event. I changed  the RoutingService ServiceContract to : "System.ServiceModel.Routing.IDuplexSessionRouter" in order to support Full Duplex Services.

The problem is I want to throw FaultException in the MessageInspector of the RoutingService at the AfterReceiveRequest event and the Client couldn't be notified that the RoutingService has returned a value as well as he stops executing until Timeout exception raised at the client  the code will be like this:

     public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
            {
                  throw new FaultException("this is inspect error!");
            }
 

    public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
            {
                 FaultException fault = new FaultException("replace error message");
                 reply = Message.CreateMessage( reply.Version, fault.CreateMessageFault(),  reply.Headers.Action);
            }
Is there anyway to make the client notify for the Faultexception thrown by RoutingService MessageInspector.

Thank you guys.