WCF Configuring server to remember data

这一生的挚爱 提交于 2019-12-06 01:15:44

Sounds like maybe you're looking for a WCF Durable Service (link). Durable services can keep state between calls to a service.

Chapter 4 in Juval Lowy's Programming WCF Services (link) also has information about Durable Services as well as per-session services which might also help.

In general, though, it's considered good practice to make your WCF services stateless - i.e. don't hold onto any state between calls. Durable services accomplish this by persisting data, for example to a database between calls instead of actually keeping it in memory (which could be a bad thing if you have thousands of simultaneous service consumers).

How is your service configured with regards to instancing/concurrency? Sounds like you might be using a singleton service instance, and storing the data in the service instance?

If so that explains your problem - that state is going to get overwritten by the next client who invokes a state changing operation.

As your client is a web browser, you are probably using the webHttpBinding which does not support WCF sessions.

One simple way to add your own session concept is to pass a session ID to your operation, which you can then use to lookup the relevant state for the requests.

If you want to get a bit more sophisticated you can investigate digging out cookie information from the WCF requests and use that for your session.

The most complicated solution is to use a custom WCF binding that supports the WCF session concept (built on top of either cookie or session parameters). Probably not worth the effort unless you can google a ready-made solution.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!