title: WCF client inspector get name of web service it calls or calling method name or type or something
body: <p>I have implemented a WCF inspector in my client application that consumes numerous web services.  </p>
  
  <p>I am using this inspector as a logging mechanism to log calls sent from the application to those web services and the responses they give back.</p>
  
  <pre><code>public class WcfClientInterceptor : IClientMessageInspector
      {
  
          protected static readonly ILog log4net = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  
          private static readonly IMessageLogger Logger = new Log4NetLogger();
  
          private MessageLogEntry LogEntry;// = new MessageLogEntry();
  
          public void AfterReceiveReply(ref Message reply, object correlationState)
          {   
  
              if (Logger.IsLogEnabled)
              {
                  LogEntry.ResponseBody = reply.ToString();
                  Logger.Log(LogEntry);
              }
          }
  
          public object BeforeSendRequest(ref Message request, IClientChannel channel)
          {
              if (Logger.IsLogEnabled)
              {
                  LogEntry = LogEntry ?? new MessageLogEntry();
                  //instanceContext.GetServiceInstance().GetType().Name
                  //LogEntry.WebServiceIdentity = request.Headers.Action;
                  LogEntry.WebServiceIdentity = OperationContext.Current.IncomingMessageHeaders.Action;
                  LogEntry.RequestBody = request.ToString();
              }
              return null;
          }
      }
  </code></pre>
  
  <p>My problem is that I don't know what web service is called. I want to get some kind of reference to them and log it.<br>
  This is the only method that works request.Headers.Action but it doesn't always work. Most of the time this is String.Empty.
  OperationContext.Current is null which I understand is normal on the client side.</p>
  
  <p>Is there any other way of getting the name of the webservice that is called?
  or the name of the calling method? or something?</p>
  
  <p>Thank you</p>