RX: Best approach to async download a list of something from a WCF-service?

只愿长相守 提交于 2020-01-06 15:06:48

问题


The result Im after is a list (WPF) of items that is populated one at a time async from a web service (WCF). I figured RX could be a good option for this?

My web service method is returning an array of strings (for now) and at the client-side Im using:

var list = Observable.FromAsyncPattern<string[]>(client.BeginList, client.EndList);

But now what? Im not familiar with RX at all and I feel very lost. Anyhow I guess my web service has to stream the list instead of sending it in a chunk if I want them to pop in continously?


回答1:


FromObservablePattern returns a Func<IObservable> (or possibly with arguments if the service takes any), so you call the delegate and then subscribe to the source:

var list = Observable.FromAsyncPattern<string[]>(client.BeginList, client.EndList);

list().Subscribe(items =>
{
    // items is the string[]
});


来源:https://stackoverflow.com/questions/5491137/rx-best-approach-to-async-download-a-list-of-something-from-a-wcf-service

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