如何在从 Windows Phone 7 调用的 WCF 服务中配置会话?
我有一个从 WP7 调用的服务。我知道 WP7(Silverlight) 直到今天只支持 basicHtptBinding ,不幸的是它不支持 Session,所以我不能在此服务中使用 InstanceContextMode.PerSession 和 SessionMode.Required 。但我在服务器上有一些数据,我需要在会话的基础上保存它。我有什么选择?
I have a service which is being called from WP7. I know WP7(Silverlight) only supports basicHtptBinding till today and unfortunately it doesn't support Session so I can't use InstanceContextMode.PerSession and SessionMode.Required in this service. But I have some data on server which I need to be preserve it on session basis. What options do I have?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不熟悉 Windows Phone 7 编程,但如果它允许您使用 basicHTTPContextBinding(这是 basicHTTPBinding 的一种风格),那么我建议您研究持久服务。
持久服务允许您将会话状态保存在某些持久存储中,并通过令牌通过每个新方法调用来访问它。
查看博客文章 链接。
即使您无法创建正式的持久服务,您也可以创建具有类似想法的东西 - 传递令牌(登录/用户 ID 或其他东西)并从持久存储(数据库表或其他东西)读取状态。
如果您能正常使用,请告诉我们!
I'm not familiar with Windows Phone 7 programming, but if it will allow you to use basicHTTPContextBinding, which is a flavor of basicHTTPBinding, then I suggest you look into a Durable Service.
Durable services allow you to save session state in some persistent storage and access it with each new method call via a token.
Take a look at the blog article at this link.
Even if you can't create a formal Durable service, you may be able to create something with a similar idea - pass a token (login/userid or something) and read state from persistent storage - database table or something.
Let us know if you get it working!
您可以在服务器端的静态类中使用 ConcurrentDictionary 来缓存使用用户身份作为键的对象。如果您需要长时间使用缓存,则需要将服务托管在 Windows 服务中,以避免应用程序池循环等问题。
You could use a ConcurrentDictionary in a static class on the server-side to cache the object using the user's identity as a key. If you need the cache around for a very long time, you'll want to host the service in a Windows Service, to avoid issues with app pool cycling, etc.