如何从WCF返回HttpContext.Current.Cache? [英] How to return HttpContext.Current.Cache from WCF?

查看:70
本文介绍了如何从WCF返回HttpContext.Current.Cache?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在IIS中托管的WCF服务,并希望返回驻留在IIS缓存中的数据(HttpContext.Current.Cache)
这个服务应该返回的类型最合适的选择是什么?

I have a WCF service hosted in IIS and want to return the data which is reside in the cache of IIS (HttpContext.Current.Cache) What is the most appropriate choice of type this service should return?

推荐答案

如果我是你,我不会依赖服务托管在IIS中的事实。如果您想使用其他技术托管WCF服务怎么办?我想你应该查看 memcached 这是一个更通用的缓存解决方案,它可以正常使用。 NET。

If I were you, I would not rely on the fact that the service is hosted in IIS. What if you wanted to host your WCF service with some other technology? I think you should check out memcached which is a much more general caching solution, and it works fine with .NET.

无论如何,如果你真的想使用IIS缓存,请使用 System.Web.HttpRuntime.Cache 而不是HttpContext.Current。缓存作为HttpContext并不总是可用。

Anyway, if you really want to use the IIS cache, use System.Web.HttpRuntime.Cache instead of HttpContext.Current.Cache as the HttpContext is not always available.

此外,正如 cruizer 所说,对象的实际类型完全无关紧要可序列化(即,类使用[Serializable()]属性进行修饰)。 IIS缓存本身不需要可序列化的对象,但是WCF会这样做。

Also, as cruizer said, the actual type of your objects is totally irrelevant as long as they are serializable (that is, the classes are decorated with the [Serializable()] attribute). The IIS cache itself does not require serializable objects but WCF does.

这篇关于如何从WCF返回HttpContext.Current.Cache?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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