简体   繁体   English

通过WCF(C#)从ASP.NET反馈异步运行进程

[英]Running a process asynchronously with feedback from ASP.NET via WCF (C#)

(Environment .NET 4.0 C# WCF and ASP.NET) (环境.NET 4.0 C#WCF和ASP.NET)

So this is the flow I'd like to have happen: 所以这是我想要发生的流程:

  1. User visits page. 用户访问页面。
  2. User uploads file via a control. 用户通过控件上传文件。
  3. User clicks "Commit". 用户单击“提交”。
  4. Page tells WCF service to begin "processing" this file (where a lot of behind the scenes work such as decompressing, hashing, moving, and database work happens) Page告诉WCF服务开始“处理”此文件(发生很多幕后工作,如解压缩,哈希,移动和数据库工作)
  5. As the file gets processed, the user sees feedback regarding the status of the processing via AJAX, an update panel, and a timer checking the status every N seconds. 随着文件的处理,用户会通过AJAX,更新面板和每隔N秒检查一次状态的计时器看到有关处理状态的反馈。

I added a table in the database called 'UploadProcessing' which persists the status (among other things) of the upload and I wrote the logic to process the upload on the back end which gets called by the WCF service. 我在数据库中添加了一个名为“ UploadProcessing”的表,该表保留了上载的状态(除其他外),并且我编写了在后端处理上载的逻辑,该逻辑由WCF服务调用。 As the upload is processed, it uploads the 'UploadProcessing' record with the current status of the work until it is finally completed. 在处理上载时,它将上载具有工作当前状态的“ UploadProcessing”记录,直到最终完成。

I first started with just calling the WCFClient.ProcessUpload(args...); 我首先从仅调用WCFClient.ProcessUpload(args...); from the Commit_Click() event, but that just processed the upload and waited until it was complete before enabling the AJAX update status timer which always showed that it had already completed (because it had). Commit_Click()事件中获取,但仅处理了上传并等待完成,然后再启用AJAX更新状态计时器,该计时器始终显示已完成(因为已完成)。 Then I tried calling the same method asynchronously but it appeared to function in the same way because the page wouldn't fully post back to the client (with the enabled timer) until the async complete handler got its response, effectively resulting in the same 'completed' response to the user. 然后,我尝试异步调用相同的方法,但是它似乎以相同的方式起作用,因为在异步完成处理程序得到响应之前,页面不会完全发回到客户端(使用启用的计时器),从而有效地导致了相同的“已完成”对用户的回复。

So what I'm politely and respectfully asking the community is how would you 'fire and forget' this ProcessUpload() method via WCF so it can do its thing in the background while the page is free to async postback and monitor its status? 因此,我有礼貌地向社区询问,您将如何通过WCF来“触发并忘记”此ProcessUpload()方法,以便它可以在后台执行其操作,同时页面可以自由地异步回发并监视其状态? Perhaps some sort of ThreadPool solution on the WCF side? 也许在WCF方面有某种ThreadPool解决方案? Or maybe a slave service that monitors the 'UploadProcessing' table for pending uploads and then handles them that way? 还是从服务监视“ UploadProcessing”表中的未决上载,然后以这种方式处理?

Thank you in advance for any advice! 预先感谢您的任何建议!

Suggest making your WCF method a OneWay operation, eg 建议将WCF方法设为OneWay操作,例如

[OperationContract(IsOneWay = true)]
public void ProcessUpload(...)
{ 
    //etc
}

It sounds like you're going about it the right way, perhaps your Async setup of the WCF Service just wasn't quite right? 听起来您正在按照正确的方式进行操作,也许您对WCF服务的异步设置不是很正确吗? The answer to this question has some helpful links, and here's an MSDN page on Calling WCF Service Operations Asynchronously . 这个问题的答案有一些有用的链接,这是MSDN页面上的异步调用WCF服务操作

Update : It looks like this blog post covers your problem almost exactly, looks like a good resource for you. 更新 :看来此博客文章几乎完全涵盖了您的问题,对您来说似乎是一个很好的资源。

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

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