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
