Fault from ClientMessageInspector.BeforeSendRequest

I am intercepting the message in client message inspector to do validation. If the validation fails, I need generate to Sender fault. Here I had two options:

1) Throw the FaultException directly in the BeforeSendRequest.

2) Do not throw in BeforeSendRequest, but generate proper fault message object and let the infrastructure throw the error for me.

Option 1 worked. Option 2 did not work and the infrastructure sent the fault message happily to the service.

Should option 2 be working? If so, then it is a bug. If option 2 should not be working, then why not?

Thanks.

[591 byte] By [RRaghu] at [2007-12-23]
# 1

In option 2 it sounds like you're just altering the message (which is allowed) that is going to be sent to the server. This is how the MessageInspector is designed to work. So if you make any changes to the message, it will send it on its way to the server.

If you need to stop it from sending the message, then you can either do what you're doing (throwing the exception) or you can implement a custom channel where you can create your own fault envelope and 'send' it back to the client. The client caching sample is similiar here. You can take a look at that to get you started.

http://wcf.netfx3.com/files/folders/transport_channels/entry3782.aspx

Thanks!

Scott

ScottMason-MSFT at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...

Visual Studio Orcas

Site Classified