How we can use RX framework in WCF for long running process and frequent UI updation?

前提是你 提交于 2020-01-03 05:22:12

问题


Recently i came to know about Rx framework and seems very promising. I have a doubt in it. Suppose from my UI [may it be winforms or web pages], i make a call to webservice and sending a List. So my calls is like --> myWCFServiceMethod(List empLists). Inside this service methods, for each employee object, i need to make again another service calls and get the result of it and do some kind of DB operations [saving and updation] and finally sends back the status of each employee to the client side. For each employee in the lists, i have to do the same operation parallel. There is no sequential order.

Is that possible with Rx framework ? For doing this, should I need to implement callback contracts for each employees status updation back to client UI ?

I made the UI with a datagrid and the datagrid has 2 columns. firts is the employee name and second is the status column.

when UI loads, i loaded with 100 employee in the grid. Then clicks on the start button. So I packed up all the employee object into a list and sends that lists to the webservice method.

Now, i am looking for the things to do which is the status updation of each process when an employee goes through different process. Something like parallel process. There is no sequential process. If some employee object can finish its work early and some others will take some time. SO there is no order of process. Any employee can call its own associated external web service call and gets the result from it. One it got such a result, it then tries to save or update the DB. For all these process, I want to get notified the status of each process of an employee is going through and finally it finishes its work.

I dont understand without having callback contract how Rx can do this ?

I didnt see any similiar type of tutorials or guidance for how we can do it.

Please guide me through proper way.

Thanks very much.


回答1:


Here's a quick answer to your question.

To make multiple service calls in parallel and then get the results as they return you need a query like this:

var query =
    from index in indexes.ToObservable()
    from result in webServiceCall(index)
    select new { index, result };

The webServiceCall signature would look like IObservable<R> webServiceCall(I index).

You then execute the query with:

query.Subscribe(ir =>
{
    // Do stuff with ir.index and ir.result
});

Focus on implementing webServiceCall to fit this code. I hope this gives you a starting point.



来源:https://stackoverflow.com/questions/14437506/how-we-can-use-rx-framework-in-wcf-for-long-running-process-and-frequent-ui-upda

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