简体   繁体   English

从GUI何时何地调用Web服务

[英]When and where to call webservice from GUI

We have an application that can be used to view the current quantity of products available for sale. 我们有一个应用程序,可用于查看可出售产品的当前数量。 The user has a GUI to create filters, for example, all black products of at least 1kg. 用户具有用于创建过滤器的GUI,例如,所有重量至少1kg的黑色产品。 When the user changes the filter, a service call with the filter descriptions is made and the results are shown in charts. 当用户更改过滤器时,将进行带有过滤器描述的服务调用,结果将显示在图表中。 The service call is very slow, say 5 seconds. 服务呼叫非常缓慢,例如5秒钟。 This in itself it not a problem. 这本身不是问题。

The problem lies in changing the filters. 问题在于更换过滤器。 What, in the user interface code, is the right place to make the call to the webservice. 在用户界面代码中,什么是调用Web服务的正确位置。
I could place a CallWebService() line in all button_pressed and lost_focus events. 我可以在所有button_pressed和lost_focus事件中放置Call​​WebService()行。 This does not feel right somehow. 这感觉不对劲。
I could also register to the collection_changed and property_changed events in the data model and call the webservice there. 我还可以在数据模型中注册到collection_changed和property_changed事件,并在那里调用Web服务。 This results in several calls when all elements from list are removed. 当列表中的所有元素都被删除时,这将导致多个调用。 We currently have a controller class in between that is called from the GUI (button_press events etc.) but inside the controller several methods call each other wich has double service calls as a result. 当前,我们在两者之间有一个从GUI调用的控制器类(button_press事件等),但是在控制器内部,多个方法相互调用,从而导致两次服务调用。

We use a data model, a view and a controller in combination with WPF and databinding However, we have had problems like these in other applications and I am wondering what the right place/event is to place the call to the webservice. 我们将数据模型,视图和控制器与WPF和数据绑定结合使用。但是,在其他应用程序中却遇到了类似的问题,我想知道将调用Webservice放在正确的位置/事件是什么。 I would like to avoid asynchronous programming and in my perception my problem has nothing to do with asynchronous programming. 我想避免异步编程,并且我认为我的问题与异步编程无关。

I suggest call service when user stop entering filter with some delay (say 5 seconds or even less). 当用户停止进入过滤器并延迟一段时间(例如5秒或更短)时,我建议致电服务部门。

Also if you want avoid ui frezing you can use Background worker class for web service calls(and while thread will work show progress image for the user). 另外,如果您想避免UI争吵,则可以将Background worker类用于Web服务调用(而线程将为用户显示进度图像)。

You should different between triggering a web service call from actually making the call. 从实际发出呼叫到触发Web服务呼叫,您应该有所不同。 For example, you can trigger the call on any change mechanism (for example - data model changes or UI events like button press). 例如,您可以在任何更改机制上触发调用(例如-数据模型更改或UI事件,例如按下按钮)。 A trigger would (re)start the timer to make the service call. 触发器将(重新)启动计时器以进行服务调用。 Key is to restarting the existing timer every time event is arrived. 关键是每次事件到达时都重新启动现有计时器。 By choosing a good value for timer say 1-2 seconds, you can actual make service call when there is pause in user's action. 通过为计时器选择一个合适的值(例如1-2秒),您可以在用户操作暂停时实际拨打服务电话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM