将 ASP.NET 会话状态与 Silverlight (PRISM) 结合使用
场景: 我有一个在 Silverlight (4) 中开发的 PRISM 应用程序,并且我正在使用 ASP.NET 服务器端应用程序来托管多个 Web 服务(依次访问 WCF 服务,但这在这里并不重要)。 Silverlight 应用程序必须能够跨域调用 Web 服务(这意味着 Web 服务不一定位于托管 silverlight 应用程序的同一服务器上)。
Silverlight 应用程序由多个模块组成,每个模块都访问 ASP.NET Web 服务。
我对 Silverlight 和 PRISM 没有太多经验,但据我所知,这并不是一个非常不寻常的场景......
问题: 我的挑战是,当 2 个不同的模块访问 Web 服务时,我在 Web 服务器上获得 2 个新会话。我本以为,由于两个模块都位于同一个 HTML 页面上(然后也在同一个浏览器会话中),因此它们会在网络服务器上获得相同的会话......?
我尝试通过注册一个实例(使用 Container.RegisterInstance)使 Web 服务代理客户端在容器中全局可用(使用 Unity),然后在模块需要进行 Web 服务调用时获取此实例(使用Container.Resolve),但这似乎没有帮助。
但是,在同一模块内进行的任何调用始终会在服务器上获得相同的会话。
谁能看到我在这里缺少什么......?
谢谢!
乔恩
The scenario:
I have a PRISM application developed in Silverlight (4), and I'm using a ASP.NET server side application to host several web-services (which, in turn, accesses WCF-services, but that's not really important here). The Silverlight application must be able to call the web services cross-domain (meaning that the web services isn't necessarily on the same server hosting the silverlight application).
The Silverlight application consists of several modules, each accessing the ASP.NET web-services.
I do not have much experience with Silverlight and PRISM, but as far as I can see, this is not a very unusual scenario...
The problem:
My challange is, that when 2 different modules access the web-services, I get 2 new sessions on the web-server. I would have thought that since both modules live on the same HTML-page (and then also in the same browser session), they would get the same session on the web-server...?
I have tried to make the web-service Proxy-client globally available in the container (using Unity), by registering an instance (using Container.RegisterInstance), and then getting this instance whenever a module needs to make a web-service call (using Container.Resolve), but this doesn't seem to help.
However, any calls made within the same module always gets the same session on the server.
Can anyone see what I'm missing here...?
Thanks!
Jon
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来我找到了自己的答案。
问题是我的应用程序在启动时触发多个 Web 服务调用(不同的 PRISM 模块独立工作)。当在 Web 服务器给出任何响应之前进行多次调用时,在进行后续调用之前,不会向客户端返回任何会话(因此不会提供“ASP.NET_SessionId”cookie)。
我的解决方案是确保我进行一次调用(一如既往地异步),例如对一个简单的类似 Ping 的 Web 服务,然后保留对 Web 服务器的所有其他调用,直到返回此响应。然后,所有后续调用都会在服务器上获得相同的 Session(因为现在它们都在标头中包含“ASP.NET_SessionId”cookie)。
实际上,这个调用是由 PRISM-shell 发出的,在我收到响应之前没有加载任何模块。然后我绝对确定在我手头有会话状态之前,其他模块都不会高兴地触发。
不过,如果有人发现此解决方案有任何其他问题,我非常高兴收到您的来信。
谢谢!
乔恩
Looks like I found my own answer.
The problem was that my application was firing multiple web-service calls upon startup (the different PRISM-modules working independently). And when several calls were made before any responses was given from the web-server, no session (and hence no "ASP.NET_SessionId" cookie was provided) back to the client before subsequent calls were made.
My solution was to make sure I make one call (async as always), for example to a simple Ping-like web-service, then hold all other calls to the web-server until this response is back. Then, all subsequent calls are given the same Session on the server (because now they all contain the "ASP.NET_SessionId" cookie in the header).
In pratice, this call is made by the PRISM-shell, and no modules are beeing loaded before I receive the reponse. Then I'm absolutely sure that none of the other modules get trigger-happy before I have a session-state on hand.
Still, if anybody sees any other problems with this solution, I'm more than happy to hear from you.
Thanks!
Jon