Prashant
Prashant

Reputation: 721

asynchronus operation in WCF

I am using c# language. Simple WCF service which has method "MethodA" this is doing time consuming heavy job. So for application performance i have created service proxy and choose option "Generate asynchronous operations". Now at client side i got few more method "BeginMethodA" , "EndMethodA". Now i called "BegineMethodA" and pass appropriate parameter. At client side i have callback method which actually returning me the result for "MethodA". I dont even call "EndMethodA". What is significant use for "EndMethodA" do i need to call this method to complete the operation?

Upvotes: 2

Views: 40

Answers (1)

BradleyDotNET
BradleyDotNET

Reputation: 61339

Yes, you do need to call EndMethodA. You do this in the async callback to get the actual results (if it has a return value).

Note that there are two ways to make this easier.

  1. Just use Task. You can actually await across the WCF channel.
  2. If you already have Begin/End methods, use Task.Factory.FromAsync and await that.

Both methods are much cleaner from a client perspective and allow you to ignore the ugliness/confusion in the old Begin/End pattern.

Upvotes: 1

Related Questions