解决阻塞问题时,同时呼吁Silverlight的WCF服务的多种方法 [英] Resolve blocking issues when simultaneously calling multiple methods on a WCF service from Silverlight

查看:297
本文介绍了解决阻塞问题时,同时呼吁Silverlight的WCF服务的多种方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经刚读关于从Silverlight的WCF服务调用同时多种方法这个有趣的文章:

I've just read this interesting article regarding simultaneously calling multiple methods on a WCF service from Silverlight:

<一个href=\"http://weblogs.asp.net/olakarlsson/archive/2010/05/20/simultaneously-calling-multiple-methods-on-a-wcf-service-from-silverlight.aspx\" rel=\"nofollow\">http://weblogs.asp.net/olakarlsson/archive/2010/05/20/simultaneously-calling-multiple-methods-on-a-wcf-service-from-silverlight.aspx

文章说的事实证明,这个问题是建立在Silverlight,Asp.Net和WCF的组合,基本上如果你做多次调用 WCF Web服务,你必须Asp.Net会话状态启用,调用将依次通过该服务,因此,任何长时间运行的调用将被阻塞后续的执行。

The article states: "It turns out that the issue is founded in a mix of Silverlight, Asp.Net and WCF, basically if you’re doing multiple calls to a single WCF web-service and you have Asp.Net session state enabled, the calls will be executed sequentially by the service, hence any long running calls will block subsequent ones."

我假设阻塞只是一个问题,如果你的相同服务进行多次调用,并在两个不同服务的两个不同的方法两个同时发生的调用不应导致一种封闭其他?

I am assuming that the blocking is only an issue if you are making multiple calls to the same service, and that two simultaneous calls to two different methods on two different services should not result in one blocking the other?

建议的解决方案,在SL3问题涉及使用以下语法在Application_Startup方法:

The suggested solution to the problem in SL3 involves using the following syntax in the Application_Startup method:

WebRequest.Register preFIX(HTTP://,WebRequestCreator.ClientHttp);

会话状态便要维持在WCF通过塞汀一个cookie的容器中,并在所有代理共享它(见的 http://forums.silverlight.net/forums/p/174322/393032.aspx

The session state will then have to be maintained on WCF calls by seting up a cookie container, and sharing it across all of your proxies (see http://forums.silverlight.net/forums/p/174322/393032.aspx)

这仍然是Silverlight 4中推荐的解决方案?有没有人使用的另一种方法?

Is this still the recommended solution in Silverlight 4? Has anyone used an alternative approach?

推荐答案

如果你正在打电话到ASP.Net应用程序,并且使用的是会话cookie,然后点击所有呼叫进入应用程序被序列化(除了那些地方页明确选择会话状态出来)。

If you are making a call into an ASP.Net application, and you are using session cookies, then all the calls into the application are serialized (apart from ones where the page explicitly opts out of session state).

通常这不是一个大问题,因为客户端浏览器通常打一个ASP.Net页面再加上一堆资源(图片,JS,CSS等),而后者的不会被映射到ASP.Net 的IIS使他们提供了原生。但是,如果你试图在打两人同时ASP.Net页面(在框架如)你会看到他们装载了一个又一个。

Normally this isn't a big issue, because a client browser typically hits an ASP.Net page plus a bunch of resources (images, js, css etc...), and these latter aren't mapped to ASP.Net so IIS serves them up natively. But if you try and hit two ASP.Net pages at the same time (eg in a frameset) you will see them load up one after another.

现在我不的知道的,出现这种情况与WCF,但根据你说的话,如果你看到一个服务,它的行为我希望看到,对所有的人,因为会话是每个用户,而不是每个服务。

Now I don't know that this happens with WCF, but based on what you say, if you see that behaviour for one service I would expect to see that for all of them, because the session is per-user, not per-service.

在ASP.Net可以会话状态的逐页的基础页面上的退出。如果对于一个承载WCF服务,可行的您的情况可能(使无国籍的服务),将aleviate问题。或将一个或多个服务到不同的ASP.Net应用程序(不同的会话)

In ASP.Net you can 'opt out' of session state on a page by page basis. If that's possible for a hosted WCF service, and viable for your scenario (to make the services stateless) that would aleviate the issue. Or move one or more services to a different ASP.Net application (different session)

记住,你可以在这里看到的其他问题与该服务的实例化和重入的模式做。如上所述的问题是每个用户的并发性的问题,但也有其他人。例如,如果你设置了服务作为一个单身(InstanceContextMode.Single)和非折返(ConcurrencyMode.Single),那么的只有一个请求将永远不会在同一时间的所有用户进行处理。

Bear in mind that you can see other issues here to do with the instancing and reentrancy models of the service. Your problem as described above is a per-user concurrency issue, but there are others. For example, if you set the service up as a singleton (InstanceContextMode.Single) and non-reentrant (ConcurrencyMode.Single) then only one request will ever be processed at a time across all users.

更新:做一些DOCO阅读:

Update: Doing some doco reading:


  • WCF服务没有注册到ASP.Net的会话,除非你要求它(使用)

  • WCF服务可以在一个的每个服务的基础上选择的,使用该服务的实现[AspNetCompatibilityRequirements]属性

  • 似乎没有要选择加入,但没有选择加入会话状态的任何方式。

  • WCF services aren't enrolled into ASP.Net sessions unless you ask for it (using )
  • WCF services can on a per service basis opt in, using the [AspNetCompatibilityRequirements] attribute on the service implementation
  • There doesn't seem to be any way of opting in but not opting into Session state.

有一个很好的博客文章这个在文龙董氏网站

There's a good blog post about this on Wenlong Dong's site

因此​​,从我所看到的,你应该能够使用AspNetCompatibilityRequirementsMode.NotAllowed从ASP.Net服务完全退出个人服务。或者,离开它默认关闭的,只有选择加入需要访问ASP.Net会话(铭记的那些,除非你真的需要分享与ASP.Net相同的会话,只使用WCF的会话服务可能是一个更好的选择)。

So from what I can see you should be able to use AspNetCompatibilityRequirementsMode.NotAllowed to opt out individual services completely from ASP.Net services. Alternatively, leave it off by default and only opt-in the ones that need access to the ASP.Net session (bearing in mind that unless you really need to share the same session with ASP.Net, just using WCF's session services is probably a better bet).

这篇关于解决阻塞问题时,同时呼吁Silverlight的WCF服务的多种方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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