BrainDump
  Home arrow BrainDump arrow Page 4 - Building Blocks for a WCF Service Web Site
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 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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

Building Blocks for a WCF Service Web Site
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-04-24

    Table of Contents:
  • Building Blocks for a WCF Service Web Site
  • Client behaviors
  • Proxy Initialization
  • Hosting a Service in IIS

  • 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


    Building Blocks for a WCF Service Web Site - Hosting a Service in IIS


    (Page 4 of 4 )

    How messages reach a service endpoint is a matter of protocols and hosting. IIS can host services over HTTP protocol, the Windows Activation Service (WAS) can
    support others such as TCP and named pipes, and self-hosting can support many protocols and includes several deployment options such as console or Windows Forms applications and Windows services. Selecting a hosting environment has nothing to do with service implementation, but everything to do with service deployment and overall system design.

    This lab will show you how to host an existing service type as part of a web site hosted in IIS. In the process, I'll also be illustrating other extended concepts such as:

    • The WCF Service web site template
    • Message-based activation
    • Additional metadata behavior settings
    • Exporting service descriptions
    • Consuming service description documents to generate client code

    As always, after the lab I'll describe some of these features in greater detail.


    Lab: Creating an IIS Host and Browsing Metadata


    For this lab, you will work with an existing solution that contains a completed service library and shell client application. Using Visual Studio templates, you'll create a new IIS web site project that contains a service and modify it to host a preexisting service. To consume the service, you'll generate a client proxy from static service documentation exported using SvcUtil.

    Creating a WCF Service web site

    The first thing to do is create a WCF-enabled web site using the WCF Service template, which is new to WCF. When services are added to a web site, the supplied sample service is accompanied by a .svc file, the web server endpoint.

    1. Open the startup solution for the lab, located at <YourLearningWCFPath>\Labs\ Chapter1\IISHostedService\IISHostedService.sln. This solution contains a copy of theHelloIndigoproject from earlier labs and a shell client application.
    2. You are going to create a new web site to host the service. Go to Solution Explorer, right-click the solution node and select Add -> New Web Site. Select the WCF Service template and make sure the location type for the new web site is HTTP (see Figure 1-25). Set the location value to http://localhost/IISHostedService.

      When Visual Studio creates a new HTTP web site, a virtual application is created in IIS pointing to a directory beneath c:\inetpub\wwwroot (or wherever your Default Web Site is pointing). In Figure 1-25, the path to theIISHostedServiceproject might be c:\ inetpub\wwwroot\IISHostedService.
    3. The WCF Service template generates a new web site with a default service implementation. You can delete the service implementation since you will be hosting an existing service. Go to Solution Explorer and expand the App_Code folder for the web site (see Figure 1-26). There you'll see the file Service.cs. Delete it from the project.
    4. Go to the web site project and add a reference to theHelloIndigoproject, which contains the service you're about to host.
    5. You now can modify the web endpoint for the service so that it is associated with the correct service type. Open Service.svc in the code window and modify the@ServiceHostdirective to associate the web endpoint with the service typeHelloIndigo.HelloIndigoService, as shown here:

        <%@ ServiceHost Service="HelloIndigo.HelloIndigoService" %>

      Now, when a request arrives to Service.svc, the service model will activate a newServiceHostinstance associated with theHelloIndigoServicetype.
    6. The WCF Service template also generated configuration settings for the host, but these settings are based on the service supplied by the template. You must modify these settings to reflect the correct service contract and service type.

      Open the web.config file and find the<service>section. Change the name attribute of the<service>section toHelloIndigo.HelloIndigoServiceand change the contract attribute of the<endpoint>section toHelloIndigo.IHelloIndigoService. While you're at it, change the binding tobasicHttpBindinginstead ofwsHttpBinding. The result is shown here:

        <service type="HelloIndigo.HelloIndigoService"
        behaviorConfiguration="returnFaults">
          <endpoint contract="HelloIndigo.IHelloIndigoService"
        binding="basicHttpBinding"/>
        </service>

    You now have a web site that will expose an endpoint to reachHelloIndigoService. Before generating the client proxy, I'll show you some useful metadata features.

    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...
     

    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

    - Internet Explorer 8 Review
    - Nilpo`s Top Windows Add-Ons
    - Beginning Silverlight 2.0 Development using ...
    - Fixing Vista`s Troubles
    - Preparing Windows Images for Mass Deployment
    - The Trouble With Vista
    - Slipstreamed and Unattended Windows Installa...
    - Microsoft Office SharePoint Server
    - Microsoft Office SharePoint Designer
    - Microsoft Windows SharePoint Services 3.0
    - Microsoft Live Mesh Overview
    - XAML Brushes and Silverlight
    - Silverlight and XAML Basics
    - Immortal XP
    - XAML Basics





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT