I am using a WCF client proxy to call a web service. I am adding logging to each request using IClientMessageInspector. I want to get info out of the underlying HTTP message, and found out I can get it by the following:
public class WCFLoggingInspector : IClientMessageInspector
{
public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
var httpRequest = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name];
var method = httpRequest.Method;
return null;
}
}
While stepping through in the debugger, this works fine. However, running normally, I get an error from the Properties indexer: "A property with the name 'httpRequest' is not present"
Can anyone explain whats going on here, or an alternate way to get at the HttpRequest? (I'm also doing the same thing for AfterReceiveReply)