简体   繁体   中英

Best way to handle long running tasks on the Server WCF + Rest

We have a WCF + Rest service running on the host. I need to make a client call to the host that would initiate a long running task on the server (even up to 15 min), then check back once that process has finished to get the result. One solution is to have client checking the host every minute or so after the initial call - but that seems not very productive. Is there a way to expose some type of event through WCF so that client would be notified when the task completed on the server? What is the best approach for this type of scenario? thanks

Kind of hard to answer without more application details. But have a few alternatives (here are a few of them):

  • Use a message queue to initialize and get events when then task is done (perhaps overkill)
  • If the client is a web client and you have the possibility ta have a web socket to the client you can notify the client that the task is done
  • Perhaps (not sure this is a good idea) you can use duplex wcf contract (since you already use wcf), then the service can invoke a method on the client interface when the task is done
  • Or do a simple polling calls like you mention in your question.

Here are some more information regarding duplex contracts: https://msdn.microsoft.com/en-us/library/ms731064%28v=vs.110%29.aspx


The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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