How do i get the invoked operation name within a WCF Message Inspector

user297332 picture user297332 · Mar 19, 2010 · Viewed 12.4k times · Source

I'm doing a message inspector in WCF:

public class LogMessageInspector :
    IDispatchMessageInspector, IClientMessageInspector

which implements the method:

public object AfterReceiveRequest(ref Message request,
    IClientChannel channel, InstanceContext instanceContext)

I can get the name of the invoked service with:

instanceContext.GetServiceInstance().GetType().Name

But how do I get the name of the invoked operation?

Answer

Kent Boogaart picture Kent Boogaart · Mar 19, 2010

It's not pretty, but this is what I did to get the operation name:

var action = OperationContext.Current.IncomingMessageHeaders.Action;
var operationName = action.Substring(action.LastIndexOf("/", StringComparison.OrdinalIgnoreCase) + 1);