开发者

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

开发者 https://www.devze.com 2023-04-08 19:48 出处:网络
(Environment .NET 4.0 C# WCF and ASP.NET) So this is the flow I\'d like to have happen: User visits page.

(Environment .NET 4.0 C# WCF and 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)

  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.

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. As the upload is processed, it uploads the 'UploadProcessing' record with the current status of the work until it is finally completed.

I first started with just calling the 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). 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? Perhaps some sort of ThreadPool solution on the WCF side? Or maybe a slave service that monitors the 'UploadProcessing' table for pending uploads and then handles them that way?

Thank you in advance for any advice!


Suggest making your WCF method a OneWay operation, e.g.

[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? The answer to this question has some helpful links, and here's an MSDN page on Calling WCF Service Operations Asynchronously.

Update: It looks like this blog post covers your problem almost exactly, looks like a good resource for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号