RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


The Windows Communication Foundation: A Primer : Page 3

The Windows Communication Foundation (WCF)—formerly known as Indigo—is Microsoft's new connected systems platform for Windows. This is the first in a WCF article series covering everything from first principles and "Hello, World!" to building fully connected applications.

Your First Indigo Application: Creating the Client
The Windows Communication Foundation SDK offers a tool called svcutil.exe that creates proxy code for your client. To use it with this service, issue the following command from the command prompt, changing the URL to match your server:

   svcutil /language:C# /config:app.config
As the namespace for the service wasn't specified, the WSDL generated by .NET uses the tempuri.org Web services namespace by default. Don't confuse this with the namespace for the code (called a package in Java parlance) which is Devx.Indigo.Samples. As such, the code generated by svcutil will be called tempuri.org.cs. This is your proxy class.

To use this proxy class, you consume it within an application class as follows:

   using System;
   using System.ServiceModel;
   namespace Devx.Indigo.Samples
     class TemperatureClient
       static void Main()
         using (TemperaturesProxy proxy =
            new TemperaturesProxy("default"))
           double c = 0.0;
           double f = 0.0;
           c = 22.2;
           f = proxy.ctof(c);
             "{0} degrees C = {1} degrees F", c, f);
           f = 93.7;
           c = proxy.ftoc(f);
              "{0} degrees C = {1} degrees F", c, f);
            "Press <ENTER> to terminate client.");
You can then compile the class shown above into an executable application using the following command:

   Csc /r:System.ServiceModel.dll /t:exe 
      TemperatureClient.cs tempuri.org.cs
When you execute the application, it calls the Indigo service, performing a Fahrenheit-to-Centigrade (FtoC) and Centigrade-to-Fahrenheit (CtoF) conversions and returning the results.

The Windows Communication Foundation is extremely powerful and flexible technology, and will become a huge part of many developers' toolboxes in the coming years. It solves two major problems: diverse communications frameworks and proliferating standards. It's a one-stop shop for all types of communication built on well-known, industry-accepted standards—and it does all that using a paradigm already familiar to most Visual Studio.NET developers. At first it might seem difficult to grasp the meanings of terms such as binding, contracts and the like, but with a little practice and a little hands-on work those soon become second nature.

The WCF application discussed in this article—a very simple service/client pairing that uses the ServiceModel framework to communicate—didn't do anything beyond what you can do with a common Web service, but it should have given you a taste of what is to come with WCF. Over the next few months the upcoming articles in this WCF series will empower you to hit the ground running in building Service Oriented Applications and software as a service on demand.

Laurence Moroney is a freelance enterprise architect who specializes in designing and implementing service-oriented applications and environments using .NET, J2EE, or (preferably) both. He has authored books on .NET and Web services security, and more than 30 professional articles. A former Wall Street architect, and security analyst, he also dabbles in journalism, reporting for professional sports. You can find his blog at http://www.philotic.com/blog.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date