这是您的问题的外围,但您是否考虑过来自需要 10 分钟以上才能返回的方法的异步回调,然后让进程在单独的线程中运行?让服务调用同步等待 10 分钟并不是一个很好的做法,并且可能会解决您的问题,尽管该服务应该允许同时允许多个调用者(我们的 WCF 服务需要数千个同时请求)。
当您调用 WCF 时,您可以选择同步或异步调用它。同步调用等待响应在同一操作中发送回调用者。在调用者中,它看起来像“myresult = svc.DoSomething()”。通过异步调用,调用者为服务提供一个函数,以便在服务完成时调用,但不等待响应。调用者在等待响应时不会阻塞并继续其业务。
您的回调将采用 DoSomethingCompletedEventArgs: void myCallback(object sender, DoSomethingCompletedEventArgs e) { var myResult = e.Result; //然后使用之前的结果。}
您像事件处理程序一样注册回调函数: svc.DoSomethingCompleted+=myCallback; 然后是 svc.DoSomethingAsync()。请注意,该语句中没有返回值;该服务将在完成时执行 myCallBack 并传递结果。(来自 Silverlight 的所有 WCF 调用都必须是异步的,但对于其他客户端,此限制不存在)。
这是一篇 codeproject 文章,详细演示了一种略有不同的方式。
http://www.codeproject.com/Articles/91528/How-to-Call-WCF-Services-Synchronously-and-Asynchr
这可以防止客户端在 10 多分钟的过程中阻塞,但并没有真正改变服务本身的运行方式。
Now the second part of what I was mentioning was firing off the 10+ minute process in a separate thread from inside the service. The service methods themselves should be very thin and just be calling functionality in other libraries. Functions that are going to take a long time should ideally be called in their own threads (say a backgroundworker, for which you register on the service side a callback when it completes) and have some sort of persistent system to keep track of their progress and any results that need to go back to the client. If it were me I would register the request for the process in a db and then update that db with its completion. The client would then periodically initiate a simple poll to see if the process was completed and get any results. You might be able to set up duplex binding to get notified when the process completes automatically but to be honest it's been a few years since I've done any duplex binding so I don't remember exactly how it works.
These topics are really too big for me to go into depth here. I would suggest researching multithreaded operations with the BackgroundWorker.