views:

207

answers:

1

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?

+1  A: 

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);

HTH,
Kent

Kent Boogaart
@svrist: don't know what you mean. That code *will* get you the operation name of the currently invoked operation.
Kent Boogaart
Sorry, that'll teach me for copy/pasting my code without checking it. Just edited for you.
Kent Boogaart
@Kent: Thank you for your answer. It works like a charm.