How to detect user agent in WCF web service

前端 未结 5 1450
广开言路
广开言路 2021-01-05 17:36

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 wis

相关标签:
5条回答
  • 2021-01-05 17:54

    You can use also:

    WebOperationContext.Current.IncomingRequest.UserAgent

    0 讨论(0)
  • 2021-01-05 17:55

    What a totally unhelpful response!

    This is not a trivial task. Yes it is obviously possible to get te user-agent string but how does one actually do it? I spent 2 hours checking google and so on but found the answer buried in MSDN documentation. In Visual Studio, from within a WebMethod try

    this.Context.Request.UserAgent

    That should do it!

    0 讨论(0)
  • 2021-01-05 17:56

    User-Agent is a standard HTTP header. It'll be available to your web service just like it's available to anything CGI-like.

    Did you even bother searching for this before posting your question? There must be millions of hits for it on Google.

    0 讨论(0)
  • 2021-01-05 18:14

    There is another way to get the user agent without enabling ASP.NET compatibility in web.config:

    string userAgent = WebOperationContext.Current.IncomingRequest.Headers["User-Agent"];
    0 讨论(0)
  • 2021-01-05 18:20

    You can read user agent from the HttpContext.Current.Request object if you enable ASP.NET compatibility in web.config:

    0 讨论(0)
提交回复
热议问题