BrainDump
  Home arrow BrainDump arrow Generating Clients and Services with Indig...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
BRAINDUMP

Generating Clients and Services with Indigo
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-04-10

    Table of Contents:
  • Generating Clients and Services with Indigo
  • Configuring service endpoints using the Service Configuration Editor
  • Generating a proxy with Add Service Reference
  • Generating a proxy using the Service Model Metadata Utility

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Generating Clients and Services with Indigo


    (Page 1 of 4 )

    In this fifth part of a ten-part series on the Windows Communication Foundation (WCF), aka Indigo, you'll learn how to use tools to generate clients and services. This article is excerpted from chapter 1 of the book Learning WCF A Hands-on Guide, written by Michele Leroux Bustamante (O'Reilly, 2007; ISBN: 0596101627). Copyright © 2007 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

    Lab: Using Tools to Generate Clients and Services 

    In this lab, you will generate service code using two approaches: by adding a service to an existing host and by generating a new service library, both using Visual Studio templates. To configure service endpoint for the host, this time you'll use the Service Configuration Editor. To generate client proxies and related configuration you'll use the ServiceModel Metadata Utility (SvcUtil). Both of these tools are available through the Solution Explorer in Visual Studio.

    Visual Studio extensions for WCF will be part of the next release of Visual Studio, code-named "Orcas." As such, the user interfaces and features of these extensions may change from the time of this writing.

    Using the WCF Service template

    In this first section of the lab, you'll create a new service using the WCF Service template and add it to an existing project. This template will add a sample service contract and service type to the project, along with the required service model assembly references. Since you will be adding the WCF Service to an executable project (the host), the template will also generate some code for hosting the service.

    1. Start by opening an existing Visual Studio solution that contains two projects: a shell console client and host. The solution is located at<YourLearningWCFPath>\ Labs\Chapter1\HelloIndigo\HelloIndigo.sln.
    2. First, you will add a new service to the host project. From Solution Explorer, right-click on theHostproject node and select Add -> New Item. Select the WCF Service template and name the file HelloIndigoService.cs.
    3. Open HelloIndigoService.cs in the code window and add a namespace qualifier for the service contract, then modify the service operation name and signature to match the following code in bold:

        [ServiceContract(Namespace=http://www.thatindigogirl.com/ samples/2006/06)]
        public interface IHelloIndigoService
        {
          [OperationContract]
         
      string HelloIndigo();
       
      }

    4. Modify the service implementation in the same file to implement the correct operation signature. This is how the resulting service type should look:

        public class HelloIndigoService : IHelloIndigoService
        {
          public string HelloIndigo()
          {
            return "Hello Indigo";
          }
        }

    5. The WCF Service template also generated a helper class for hosting the service, namedMyServiceHost, located beneath the service type. You're going to edit this class and remove the hardcoded base address provided to theServiceHostinstance.

      Locate theStartService()method inMyServiceHostand modify it so that a base address is no longer passed to theServiceHost constructor. The resulting changes are shown here:

        internal static void StartService()
        {

          myServiceHost = new ServiceHost(typeof(HelloIndigoService));
          myServiceHost.Open();
        }

    6. You're going to use the hosting helper class to initialize theServiceHost for the service. Go to theHostproject and open Program.cs. Modify theMain()entry point so that it looks as follows:

        static void Main(string[] args)
        {
          try
          {
            MyServiceHost.StartService();
            Console.WriteLine("Press <ENTER> to terminate the host application");
            Console.ReadLine();
          }
          finally
          {
            MyServiceHost.StopService();
          }
        }

    7. Compile theHostproject.

    At this point, you have defined a service inside theHostproject and added code to host the service, but the implementation is incomplete. TheServiceHostrequires at least one endpoint before clients can invoke the service.

    More BrainDump Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Learning WCF A Hands-on Guide," published...
     

    Buy this book now. This article is excerpted from chapter 1 of the book Learning WCF A Hands-on Guide, written by Michele Leroux Bustamante (O'Reilly, 2007; ISBN: 0596101627). Check it out today at your favorite bookstore. Buy this book now.

    BRAINDUMP ARTICLES

    - Introduction to Office Live Workspace
    - Using MS Excel for One-way Analysis of Varia...
    - Comparing Data Sets Using Statistical Analys...
    - Import Blogger Posts into WordPress Using Wi...
    - Download WordPress from an FTP Server and Ru...
    - Install and Run WordPress in XAMPP Local Host
    - What Windows 7 Brings to the Table
    - Virtualization and Sandbox Detection
    - Advanced Firebug Techniques in Windows XP Ho...
    - Editing CSS with Firebug in Windows XP Home
    - Using Firebug in Windows XP Home
    - Migrating to Exchange Server 2007
    - Using System Restore on a Non-Bootable PC
    - Finding Logged on Users and More Scripting S...
    - Developing Macro Commands in MS Excel





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek