How to automate task of consuming webservice

前端 未结 2 674
臣服心动
臣服心动 2021-01-23 04:35

I have a winform application which needs to consume a web service. Web service checks in the database for any changes. If there are any changes

相关标签:
2条回答
  • 2021-01-23 05:16

    SignalR allows you to implement Web Services to do this very thing, in real time (no need for a timer or delay between updates). It allows you to set up a persistent connection between client and server, the server is then able to send messages to the client at any point using a stack of transports; WebSockets, Server Sent Events, Forever Frame and Long Polling) based on support available in that order.

    You could use SignalR to establish the connection and when something happens on the Server (such as the change in the database you mentioned) broadcast to all clients that need to be notified. eg.

    Clients.All.notifyDatabaseChanged(args);
    
    0 讨论(0)
  • 2021-01-23 05:30

    That's the only way especially if the web service is not WCF-based or if you can't afford to modify it.

    If you're using a timer just make sure you use System.Timers.Timer and follow the instructions here so that the Elapsed handler is executed on the UI thread. Moreover, when the timer ticks you should probably spawn a worker thread (or Task, or await on an async method) that makes the service call. You don't want your UI to be blocked while the service call is in progress.

    If you have control over the web service, then you may want to explore WCF Duplex Services, which allow you to callback clients from within services.

    0 讨论(0)
提交回复
热议问题