Banshee
Banshee

Reputation: 15837

Get operation name in Message Inspector?

Im using the IClientMessageInspector to log in/out messages but the problem is that I can´t find how to get the operation name from AfterReceivedReply and BeforeSendRequest.

I have tested the following :

if ((action = reply.Headers.Action.Split('/').LastOrDefault()) != null)
{
   callInformation.Action = action;
   callInformation.Address = reply.Headers.Action.Replace(action, "");
}

This works fine in BeforeSendRequest but in the AfterReveivedReply it returns something different, often with the "Response" on the end?

How do I only get the operation name in those methods?

Say, that my operation is named MyOperation and a OperationContract attribute states the action = "MyOpeation" (wrong spelling). This result of this is that MyOpeation will be extracted in BeforeSendRequest while the AfterReceiveReply will return MyOperationResponse.

So the BeforeSendRequest will extract the stated action in the attribute and the AfterReceiveReply will extract the real operation name but with the add of "Response" on the end?

Its important to be able to match the in/out messages and the only way of doing this as I see it is to match the operation names but if that is not possible then I do not see a good solution to this?

I have seen solution when using OperationContext.Current.IncomingMessageHeaders.Action but the OperationContect.Current is null when doing this on the client side.

Upvotes: 5

Views: 2628

Answers (1)

Yahia
Yahia

Reputation: 70379

From your question I assume you want to match In/Out messages by any means - the framework provides for this:

In the implementation of IClientMessageInspector.BeforeSendRequest you can return a unique correlationState which in turn allows you to relate the reply message in your implementation of IClientMessageInspector.AfterReceiveReply since the Framework will call your implementation with it as the second parameter.

EDIT - as per comments below:

IF you really need to get the name of the operation/method called you could do this is by implementing IClientMessageFormatter.SerializeRequest OR IParameterInspector - this will allow you to to record which method with which parameters have been called and what Message object the framework created for it.

Upvotes: 3

Related Questions