在WCF应用程序会话变量 [英] Session variable in WCF application

查看:110
本文介绍了在WCF应用程序会话变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用或刺激一个非常简单的会话对象在我的WCF应用程序。

I need to use or stimulate a very simple session object inside my WCF app.

我只需要存储一些值在呼叫的开始,我需要访问这些值,而我通过一些不同的我的服务的方法。

I simply need to store some values at the beginning of a call and I need access to these values while I go through some different methods of my service.

Asp.NET会议将是非常理想的用于此,所以我需要找出哪些是可以在一个WCF的应用程序,用于存储这些值。

Asp.NET session would be very ideal to use for this so I need to find out what is available on a WCF app for storing such values.

请注意:这只是每个呼叫会话,我不需要保留不同的呼叫之间的会议从客户服务和这样的..

Note: this is just a per call session, I don't need to retain this session between different calls from the client to service and such..

推荐答案

你所描述的是什么(即保留单个请求的生活习俗方面)更像 HttpContext.Items 不是ASP.NET会话。

What you're describing (custom context that is retained for the life of a single request) is more like HttpContext.Items than an ASP.NET Session.

WCF确实有一类叫做的OperationContext 类似于的HttpContext 。它不具有产品属性自定义背景,但<一个href="http://web.archive.org/web/20140312141611/http://hyperthink.net/blog/a-simple-ish-approach-to-custom-context-in-wcf/"相对=nofollow>这篇博客介绍,你可以用它来实现你想要的技术。

WCF does have a class called OperationContext that is similar to HttpContext. It doesn't have an Items property for custom context, but this blog post describes a technique you can use to achieve what you want.

这篇关于在WCF应用程序会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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