BrainDump
  Home arrow BrainDump arrow Page 4 - Creating Services with the WCF
Iron Speed
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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
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

Creating Services with the WCF
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-03-27

    Table of Contents:
  • Creating Services with the WCF
  • Channels
  • Creating a New Service from Scratch
  • Hosting a service

  • 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
     
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Creating Services with the WCF - Hosting a service
    (Page 4 of 4 )

    Next, add a new console application to the solution. This will be the host application. You'll instantiate a ServiceHost instance for the service type and configure a single endpoint.

    1. Go to the Solution Explorer and add a new Console Application project to the solution. Name the new projectHost.
    2. Add a reference to theSystem.ServiceModelassembly, and add the followingusingstatement to Program.cs:

        using System.ServiceModel;
    3. You will be writing code to host theHelloIndigoServicetype. Before you can do this, you must add a reference to theHelloIndigoproject.
    4. Create aServiceHostinstance and endpoint for the service. Open Program.cs in the code window and modify theMain()entry point, adding the code shown in Example 1-1. This code initializes aServiceHostinstance specifying the service type and a base address where relative service endpoints can be located. It also adds a single relative endpoint for the service. In this case, a base address is provided for HTTP protocol, and the relative endpoint uses one of the standard bindings,BasicHttpBinding, based on HTTP protocol.
    5. Compile and run the host to verify that it works. From Solution Explorer, right-click on theHostproject node and select "Set as Startup Project." Run the project (F5), and you should see console output similar to that shown in Figure 1-17.
    6. Stop debugging and return to Visual Studio.

    Example 1-1. Code to programmatically initialize the ServiceHost

    static void Main(string[] args)
    {
      using (ServiceHost host = new ServiceHost(typeof(HelloIndigo.HelloIndigoService),
    new Uri(http://localhost:8000/HelloIndigo)))
      {
        host.AddServiceEndpoint(typeof(HelloIndigo.IHelloIndigoService),
    new BasicHttpBinding(), "HelloIndigoService");
        host.Open();

        Console.WriteLine("Press <ENTER> to terminate the service host");
        Console.ReadLine();
      }
    }


    Figure 1-17.  Console output for the host application

    You now have a host application for the service. When it is running, clients will be able to communicate with the service. The next step is to create a client application.

    Please check back next week for the continuation of this article.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · This article is an excerpt from the book "Learning WCF A Hands-on Guide," published...
       · I created the WCF service on Windows Vista. As you may have known, Vista has the...
     

    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

    - Handling Multiple Contracts with Indigo
    - Cleaning Out Your Data in XP
    - Multiple Service Contracts and Indigo
    - Cleaning Out Your Programs in XP
    - Handling Metadata with Indigo
    - Building Blocks for a WCF Service Web Site
    - Help! I Need Some Remote Assistance
    - Using Service Templates with Indigo
    - Windows XP Tips for Task Manager
    - Generating Clients and Services with Indigo
    - Vista SP1, A Review
    - Services and the WCF
    - VBScript: Final Date Functions
    - Creating Services with the WCF
    - The Resource View of the MFC

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway