RIA 服务匹配请求的响应

发布于 2024-09-25 08:33:32 字数 351 浏览 1 评论 0 原文

我想知道是否有人可以就以下问题提供一些建议。我们目前正在开发基于 RIA .NET 服务的 Silverlight 4 应用程序。应用程序中的一个屏幕允许用户输入搜索字符串,2 秒不活动后,请求将提交到我们的域服务。这一切都可以通过 Rx 很好地处理。

现在,在原始搜索返回之前可以执行第二次搜索。第二个请求也有可能在第一个请求之前返回。

实际上,我只是想找出人们使用什么模式和方法来管理对正确请求的正确响应。

您是否在请求中使用某种操作标识符? 您是否为每个请求创建域服务的新实例? 是否可以将请求的已完成事件与监视 textchange 事件的 Rx 可观察对象联系起来?

任何引导都会有帮助,

戴夫

I was wondering if someone could provide some advice on the following problem. We are currently developing a Silverlight 4 application based on RIA .NET Services. One of the screens in the application allows users to type in a search string and after 2 seconds of inactivity the request is submitted to our domain service. This is all handles nicely with Rx.

Now currently it is possible for a second search to be executed before the original has returned. Its also possible that the second request could return before the first.

Really I'm just trying to find out what patterns and approaches people are using to manage the correct response to the correct request.

Are you using some sort of operation identifier in your requests?
Are you creating new instances of your domain services for each request?
Is there away to tie the completed event of a request to the Rx observable monitoring the textchange event?

Any steer would be helpful really,

Dave

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

请叫√我孤独 2024-10-02 08:33:32

你应该很容易解决这个问题。

如果我假设您有一个可观察的字符串来启动搜索,并且您有一个域服务,在给定字符串时返回一个 Result 对象,那么这就是您需要的代码:

IObservable<string> searchText
    = ...;

Func<string, IObservable<Result>> searchRequest
    = Observable.FromAsyncPattern<string, Result>(
        search.BeginInvoke,
        search.EndInvoke);

IObservable<Result> results
    = (from st in searchText
       select searchRequest(st))
      .Switch();

神奇之处在于Switch 扩展方法,“切换”到从 IObservable> 返回的最新可观察值 - 是的,它是一个嵌套的可观察值。

当新的 searchText 传入时,查询将返回根据传入搜索文本创建的新 IObservable。然后,Switch 切换 results observable 以使用最新的 observable,并忽略任何先前创建的 observable。

因此,结果是仅观察最新的搜索结果,而忽略任何先前的结果。

希望这是有道理的。 :-)

It should be quite easy for you to solve this problem.

If I assume you have an observable of string that initiates the search and that you have a domain service that returns a Result object when given the string then this is the kind of code you need:

IObservable<string> searchText
    = ...;

Func<string, IObservable<Result>> searchRequest
    = Observable.FromAsyncPattern<string, Result>(
        search.BeginInvoke,
        search.EndInvoke);

IObservable<Result> results
    = (from st in searchText
       select searchRequest(st))
      .Switch();

The magic is in the Switch extension method which "switches" to the latest observable returned from the IObservable<IObservable<Result>> - yes, it is a nested observable.

When a new searchText comes in, the query returns a new IObservable<Result> created from the incoming search text. The Switch then switches the results observable to use this latest observable and just ignores any previously created observables.

So the result is that only the latest search results are observed and any previous results are ignored.

Hopefully that makes sense. :-)

↙温凉少女 2024-10-02 08:33:32

Erik Meijer 在此解决了这个问题(大约 30 分钟后):http://channel9.msdn.com /活动/MIX/MIX10/FTL01
他在大约 36 分钟后解释了 Switch 的声明。

Erik Meijer addresses this here (after about 30 minutes): http://channel9.msdn.com/Events/MIX/MIX10/FTL01
He explains the Switch statement after about 36 minutes.

半寸时光 2024-10-02 08:33:32

IMO 最简单的方法是为请求指定一个主题,在将任何请求分派到 WCF 之前通知您该主题。然后,不要订阅从已完成事件创建的可观察对象,而是订阅 CompletedEventObservable.TakeUntil(RequestsSubject)。这样,您将永远不会收到对先前请求的响应的通知。

The simples way IMO is to have a subject for requests that you notify before any request is dispatched to WCF. Then rather than subscribing to observable created from the completed event subscribe to CompletedEventObservable.TakeUntil(RequestsSubject). This way you will never be notified with the response to the previous request.

勿忘初心 2024-10-02 08:33:32

查看 rxx http://rxx.codeplex.com/

它有大量额外的东西可以帮助,特别是就你而言,我认为动态对象和可观察对象道具可能会让你的生活更轻松。

Check out rxx http://rxx.codeplex.com/

It has tons of extra stuff that will help, particularly in your case, I think Dynamic Objects and observable object props might be something that will make your life easier.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文