【发布时间】:2010-05-03 17:20:35
【问题描述】:
如何检测 Web 服务中的用户代理?我的 Web 服务是使用带有 basicHTTPBinding 的 WCF Web 服务实现的。这将是一些 SOAP 客户端的帖子。我想知道客户的用户代理。
我希望看到一些示例代码。
我正在使用基于 WCF 的 Web 服务,并且在 svc.cs 中,我试图捕获 this.Context.Request.UserAgent。但它给出了以下错误:
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?)
我也试过System.Web.HttpContext.Current.Request.UserAgent,它说:
'System.Web.HttpContext.Current' is null
编辑说明:
我尝试激活 ASP.NET 兼容模式。我在配置文件中添加了<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />,并在实现服务接口的类的顶部添加了[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]。然后使用 System.Web.HttpContext.Current.Request.UserAgent 为我提供所需的用户代理。
【问题讨论】:
-
这将是一些 SOAP 客户端的帖子。
标签: wcf web-services user-agent