none
user agent returns null when the client uses wcf test client RRS feed

  • Question

  • I want to log the user agents information in my log file. So I use this code:
    System.Web.HttpContext.Current.Request.UserAgent;

    It works fine when I'm using the browser to consume my web service (the user agent returns the right value) but when I use the WCF test client, it returns null string. In IIS log file user agent returns right value no matter use which application to consume the web service. I guess I miss something here but I don't now what.

    • Moved by Kristin Xie Monday, July 6, 2015 6:43 AM move to better forum
    Friday, July 3, 2015 3:33 PM

All replies

  • hi Bouki,
       According to this case, you may try to get it via OperationContext like below :

    string userAgent = WebOperationContext.Current.IncomingRequest.Headers["User-Agent"];

    Monday, July 6, 2015 8:05 AM
  • hi Bouki,
       According to this case, you may try to get it via OperationContext like below :

    string userAgent = WebOperationContext.Current.IncomingRequest.Headers["User-Agent"];

    thanks dear edwin.

    already try it. same result.

    Tuesday, July 7, 2015 5:30 AM
  • hi Bouki,
       As per this case, you may try like below :
    OperationContext context = OperationContext.Current;
    HttpRequestMessageProperty httpRequest =
          context.IncomingMessageProperties["httpRequest"] as HttpRequestMessageProperty;
    if (httpRequest != null)
    {    
      string userAgentInfo = httpRequest.Headers["User-Agent"];
    }  
    
    Tuesday, July 7, 2015 8:02 AM
  • hi Bouki,
       As per this case, you may try like below :
    OperationContext context = OperationContext.Current;
    HttpRequestMessageProperty httpRequest =
          context.IncomingMessageProperties["httpRequest"] as HttpRequestMessageProperty;
    if (httpRequest != null)
    {    
      string userAgentInfo = httpRequest.Headers["User-Agent"];
    }  

    thank you so much dear edwin.

    same result.

    user agent string in iis log file: Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+4.0.30319.34003)

    but in my log file user-agent returns null.



    • Edited by Bouki Tuesday, July 21, 2015 6:56 AM
    Wednesday, July 8, 2015 6:22 AM