How can I detect a user agent in a web service? My web service is implemented using the WCF web service with basicHTTPBinding. This will be a message from some SOAP clients. I want to know user agent from clients.
I would like to see some sample code for this.
I am using WCF-based web service, and in svc.cs I tried to catch this.Context.Request.UserAgent . But this leads to the following error:
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?)
I also tried System.Web.HttpContext.Current.Request.UserAgent and it says:
'System.Web.HttpContext.Current' is null
Change note:
I tried to activate ASP.NET compatibility mode. I added <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> to the configuration file and added [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] at the top of the class that implements the service interface. Then, using System.Web.HttpContext.Current.Request.UserAgent, gives me the user agent of his choice.
web-services user-agent wcf
Kangkan
source share