title: How to detect user agent in WCF web service
body: <p>How can I detect the user agent in a web service? My web service is implemented using a WCF webservice with basicHTTPBinding. It will be a post from some SOAP clients. I wish to know the user-agent from the clients.</p>
  
  <p>I shall like to see some sample code for this.</p>
  
  <p>I am using a WCF based web service and in the svc.cs, I tried to catch <code>this.Context.Request.UserAgent</code>. But it gives the following error:</p>
  
  <pre><code>this.Context.Request.UserAgent 'MySoapService.MyService' does not contain a definition for 'Context' and no extension method 'Context' accepting a first argument of type 'MySoapService.MyService' could be found (are you missing a using directive or an assembly reference?)
  </code></pre>
  
  <p>I also tried <code>System.Web.HttpContext.Current.Request.UserAgent</code> and it says: </p>
  
  <pre><code>'System.Web.HttpContext.Current' is null
  </code></pre>
  
  <p>Edit note: </p>
  
  <p>I tried to activate the ASP.NET compatibility mode. I added <code>&lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" /&gt;</code> in the config file and added <code>[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]</code>  on the top of the class that implements the service interface. Then using System.Web.HttpContext.Current.Request.UserAgent gives me the user agent as desired. </p>