Asynchronous Pattern in Windows Communication Foundation
page 5 of 7
by Keyvan Nayyeri
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 56034/ 229

Client

My implementation is almost done because there is nothing special on the client side. You create a proxy and call the Add() method to calculate the result (Listing 10).  Notice the name of the Add() method.  There was no service method with this name, but WCF generated this name of my method and there is no BeginAdd() or EndAdd() method available for client. Therefore, clients cannot know if a method is implemented normally or asynchronously.

Listing 10: Client Code

using System;
using System.Collections.Generic;
using System.Text;
 
namespace AsyncWCFClient
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Title = 
                "Asynchronous Pattern in Windows Communication Foundation";
 
            Console.WriteLine("Enter Number 1:");
            int number1 = Convert.ToInt32(Console.ReadLine());
 
            Console.WriteLine("Enter Number 2:");
            int number2 = Convert.ToInt32(Console.ReadLine());
 
            using (AddServiceClient proxy = new AddServiceClient())
            {
                Console.WriteLine("Wait until operation ends asynchronously ...");
                int result = proxy.Add(number1, number2);
                Console.WriteLine("Result = {0}", result.ToString());
            }
            Console.ReadLine();
        }
    }
}

The output of this console application can be seen in Figure 1.

Figure 1: The Output


View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 1 and 6 and type the answer here:

User Comments

Title: Thanks !   
Name: shibu
Date: 1/18/2011 2:34:06 AM
Comment:
is there any vb.net version
Title: thanks!   
Name: dulcissa
Date: 12/9/2010 3:54:17 PM
Comment:
thank you! very useful!
Title: Very very useful......   
Name: Devender Yadav
Date: 10/29/2010 11:16:13 PM
Comment:
Thanks for this articles
Title: Is this joke?   
Name: Jigga
Date: 7/23/2010 1:19:04 PM
Comment:
Where are You using it asynchronously? Yor client code makes no sense.
Title: Very Helpful   
Name: Ted
Date: 7/7/2010 12:05:06 PM
Comment:
Very instructive and useful
Title: Where's the Client?   
Name: Adam
Date: 6/2/2009 4:09:23 PM
Comment:
There is no call in the client side that makes use of the callback routine to discover when the operation is complete. It looks like you did a ton of work to create an asynchronous way to call the Add function, and then the client totally skips it and calls it synchrously. Am I missing something?
Title: Thanx   
Name: MC
Date: 2/21/2008 4:02:44 PM
Comment:
Very hepful !
Title: Event-Based Asynchronous Programming   
Name: Nirmala
Date: 11/23/2007 7:47:55 AM
Comment:
Why Event-Based Asynchronous Programming is not supported in WCF proxy? Is there any work around to fill the gap?
Title: InvokeAsync in WCF   
Name: Nirmala
Date: 11/23/2007 7:33:17 AM
Comment:
In WebService proxy, we have InvokeAsync (of SoapHttpClientProtocol).
But, WCF proxy is missing the InvokeAsync.

Will VS 2008/3.5 support InvokeAsync?
Title: Asynchronous Pattern in WCF   
Name: Nirmala Patthi
Date: 11/19/2007 6:02:17 AM
Comment:
Hi Keyvan Nayyeri,

Thanks for your article. Do you have any idea how to implement Async2 patten in WCF? In the dotnet WebServices, SoapHttpClientProtocol has InvokeAsync that implements Async2 pattern (that is newly introduced in asp.net 2.0 framework).
When we create a WebService proxy, it will have the InvokeAsync implemented by default.
However, when we create a WCF proxy, InvokeAsync is not generated, rather we will have BeginInvoke, EndInvoke though.
I am not sure about if dotnet 3.5 framework, if WCF will come with Async2 pattern.
Can you please comment on this?
Title: Thanks   
Name: Keyvan Nayyeri
Date: 7/13/2007 3:19:21 AM
Comment:
Thank you Darren :-)
Title: Nice!   
Name: Darren Neimke
Date: 7/13/2007 3:04:25 AM
Comment:
Nice stuff Keyvan... thanks for sharing :-)






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2012 ASPAlliance.com  |  Page Processed at 2/12/2012 1:50:48 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search