访问 WCF RequestInterceptor 中的 HttpContext
我正在使用 WCF REST stater 工具包 构建一个简单的 xml HTTP 服务。作为此部分的一部分,我使用 RequestInterceptor 进行身份验证。在 RequestInterceptor 内部,我可以访问 System.ServiceModel.Channels.RequestContext 对象,从中我可以获取请求 url、查询字符串参数和其他有用的东西。我无法解决的是如何访问请求的 HttpContext。我在 HttpContext 中存储了一些内容,我想在 requestInterceptor 中访问它们,但我很难获取它们。当我在 Visual Studio 中使用快速监视时,我可以看到它隐藏在 requestContext 的私有成员中。有人可以告诉我如何访问 HttpContext,也许使用 RequestContext 对象上的反射吗?
I am using the WCF REST stater kit to build a plain xml over HTTP service. As part of this Im using a RequestInterceptor to do authentication. Inside of the RequestInterceptor I have access to a System.ServiceModel.Channels.RequestContext object from which i can get the request url, querystring params and other helpful things. What I cannot work out is how to get access to the HttpContext of the request. I have several things stored in the HttpContext which I want to access inside the requestInterceptor but Im struggling to get to them. When I use the quickwatch inside Visual Studio I can see that it is there buried inside private members of the requestContext. Can somebody show me how to access the HttpContext, perhaps using reflection on the RequestContext object?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要打开兼容性,您就可以在 ASP.NET 托管的任何 WCF 服务内访问 ASP.NET 的 HttpContext。这通过两个步骤完成:
确保通过配置以下内容启用兼容性:
完成此操作后,您可以随时使用 静态 Current 属性。例如:
请注意,启用与 ASP.NET 运行时的集成确实会为每个请求带来一些额外的开销,因此,如果您不需要它,则可以通过不启用它而仅使用 System.ServiceModel.Web 运行时来节省一些性能。您可以使用 HttpRequestResponseMessageProperty 和 HttpResponseMessageProperty类。
有关该主题的详细信息,请参阅 MSDN 中标题为 WCF 和 ASP.NET 的部分。
You can access ASP.NET's HttpContext inside any WCF service hosted in ASP.NET as long as you turn on compatibility. This is done in two steps:
Make sure you enable compatibility by configuring the following:
Once you've done that, you can access the current HttpContext instance at any time using the static Current property. For example:
Note that enabling integration with the ASP.NET runtime does incur some additional overhead for each request, so if you don't need it you can save some performance by not enabling it and just using the System.ServiceModel.Web runtime instead. You have access to pretty much all the information you need using the HttpRequestResponseMessageProperty and HttpResponseMessageProperty classes.
For more information on the subject, see this section of MSDN titled WCF and ASP.NET.