Like any good command-line tool, svcutil.exe provides a great number of options that you can use to
control how the client proxy is generated. If you do not require these advanced options, you can
generate the same two files using the Visual Studio 2010 IDE. For the client project, simply select the Add
Service Reference option from the Project menu.
Once you activate this menu option, you will be prompted to enter the service URI. At this point,
click the Go button to see the service description
Beyond creating and inserting the proxy files into your current project, this tool is kind enough to
reference the WCF assemblies automatically on your behalf. In accordance with a naming convention,
the proxy class is defined within a namespace called ServiceReference, which is nested in the client’s
namespace (to avoid possible name clashes). Here is the complete client code:
// Location of the proxy.
using MagicEightBallServiceClient.ServiceReference1;
namespace MagicEightBallServiceClient
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("***** Ask the Magic 8 Ball *****\n");
using (EightBallClient ball = new EightBallClient())
{
Console.Write("Your question: ");
string question = Console.ReadLine();
string answer =
ball.ObtainAnswerToQuestion(question);
Console.WriteLine("8-Ball says: {0}", answer);
}
Console.ReadLine();
}
}
}
Now assume your WCF console host is running, so you can execute the client. Here is one possible
response to a question I’ve been asking quite a bit during the authoring of this edition of the book (with apologies to fine folks at Apress!)
***** Ask the Magic 8 Ball *****
Your question: Will I get this book done soon?
8-Ball says: No
Press any key to continue . . .