gpt4 book ai didi

wcf - 如何在 WCF Web 服务中检测用户代理

转载 作者:行者123 更新时间:2023-12-04 13:24:59 26 4
gpt4 key购买 nike

如何检测 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)]在实现服务接口(interface)的类的顶部。然后使用 System.Web.HttpContext.Current.Request.UserAgent 为我提供所需的用户代理。

最佳答案

您还可以使用:

WebOperationContext.Current.IncomingRequest.UserAgent

关于wcf - 如何在 WCF Web 服务中检测用户代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2759866/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com