WCF请求范围变量 [英] WCF Request Scope Variables

查看:30
本文介绍了WCF请求范围变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在做一些工作,主要使用 IOperationInvoker 扩展我的服务的WCF管道,以实现自己的功能.

I've been doing some work extending the WCF pipeline of my service using mainly IOperationInvoker to implement my own functionality.

我当前正在使用 System.Web.HttpContext.Current.Items 来存储一些我希望在我的请求的整个生命周期中都可以持久并可用的变量(在webserice方法中,方法调用前),后方法调用).

I am currently using System.Web.HttpContext.Current.Items to store some variables that I want to be be persisted and available throughout the lifetime of my request (pre method invokation, during webserice method, post method invokation).

这在使用 HTTP 绑定时可以正常工作,但是,我现在需要在 System所在的位置启用 TCP NamedPipes 绑定.Web.HttpContext.Current.Items 包显然不可用.

This works fine when using the HTTP binding, however, I now need to enable TCP and NamedPipes bindings where the System.Web.HttpContext.Current.Items bag obviously isn't available.

是否有更好的地方来存储只希望在当前请求范围内的变量?

Is there a better place to be storing variables that I only want to be in scope for the current request?

谢谢大卫

推荐答案

我认为您需要链接到 OperationContext 而不是 HttpContext .已经在此处.

I believe you need to be linked to OperationContext not HttpContext. The answer to similar question is already presented here.

基本上,您只需要实现IExtension并将其插入WCF.可以找到分步示例,例如此处.

Basically you just need to implement IExtension and plug it into WCF. Step-by-step example can be found for example here.

这篇关于WCF请求范围变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆