开发者

Making a multithreaded client method wait for a WCF service to finish before continuing with execution

EDIT: Please note that everything works as intended when I have the client solution in debug mode. The solution with the service works fine in or out of debug mode.


I'm working on a file uploader that saves a user-uploaded .zip file to the server, unzips it, copies it to a bunch of different locations from there asynchronously (using web services), and then deletes the uploaded .zip file and unzipped files.

So:

1) upload and unzips the file

2) uses QueueUserWorkItem(MethodName) and redirects the user to a "thank you" page

3) MethodName() then makes a couple WCF web service calls that copy the unzipped folder to other places.

string copyToPaths = UploaderService.StartFolderUpload(_fileCategoryName, topDir);
UploaderService.CompleteFolderUpload(copyToPaths);

4) Deletes old files once service calls have completed and the files are no longer necessary (issue here)

So my issue is that the method that calls the WCF services doesn't wait for the service calls to complete before saying its done and deletes the files. It deletes the uploaded files and then the web service obviously canno开发者_如何转开发t use those files to copy to other locations.

How can I make a method (that has been called with QueueUserWorkItem ) wait for web service calls to finish before moving on with its execution?


As far as I know, this behaviour has nothing to do with the client side. It's controlled by the OperationContract attribute on the service method.

[OperationContract(IsOneWay = true)]
void CompleteFolderUpload(string copyToPaths);

Is this what the second service method looks like? If it is, then you must set IsOneWay to false (or just remove it) if you want clients to wait for this method to complete. IsOneWay = true means that clients should not expect a response from the server, so they will almost always return before the method completes.


You may want to consider making your WCF service a Duplex service. This way you can specify a callback on the client so you know when the service has finished. It also you to pass data back to your client e.g. Error information etc

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜