BrainDump
  Home arrow BrainDump arrow 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 
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

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
     
     
    ibm
     
    ADVERTISEMENT


    Building Blocks for a WCF Service Web Site
    (Page 1 of 4 )

    In this seventh part of a ten-part series focusing on the Windows Communication Foundation (WCF), aka Indigo, you'll learn how to work with service and client behaviors, and start creating a WCF Service web site. 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.

    Working with Behaviors

    As you've seen, the ServiceHost is initialized by the <service> configuration section associated with its service type. At least one endpoint must be configured for the service to be useful to clients. In this lab, a single service endpoint and a metadata exchange endpoint are exposed--both over HTTP. While endpoints describe where to reach the service, which operations are available at the specified address, and what protocols are required--behaviors affect the service model locally at the client or service. What that means is that behaviors are not exposed as part of metadata, and they are not shared between clients and services. Instead, they locally affect how the service model processes messages.

    Behaviors can be defined in configuration or in code. Different behaviors are available to clients and services, since the local affect on the service model also differs.

    Service behaviors

    Service behaviors are types that implement IServiceBehavior from the
    System.ServiceModel.Description namespace. There are service behaviors to control debugging, metadata, security features, serialization, and throttling. When enabled, each behavior interacts with the service model to achieve its goal. For example, when the metadata behavior is enabled, the service model will allow requests to a metadata exchange endpoint. Otherwise, it will not.

    Service behaviors are configured in the<serviceBehaviors>section. The following example illustrates enabling service debug and service metadata behaviors:

      <behaviors>
         
    <serviceBehaviors>
           
    <behavior name="serviceBehavior">
             
    <serviceDebug includeExceptionDetailInFaults="true"/>
              
    <serviceMetadata />
          </behavior>
       
    </serviceBehaviors>
      </behaviors>

    To associate a set of behaviors with a service use thebehaviorConfigurationattribute of the<service>section (see Example 1-8).

    Example 1-8. Associating a service behavior to a service

    <system.serviceModel>
     
    <behaviors>
       
    <serviceBehaviors>
         
    <behavior name="serviceBehavior">
           
    <serviceMetadata />
         
    </behavior>
       
    </serviceBehaviors>
      </behaviors>
      <services>
       
    <service behaviorConfiguration="serviceBehavior" name="Host.HelloIndigoService" >
       
    ...
       
    </service>
     
    </services>
    </system.serviceModel>

    You may forget to make the association between the service and behavior at least a few times. Don't forget to double-check your configuration when you aren't seeing the expected results at runtime!

    You can also programmatically configure service behaviors through theServiceHostinstance. TheDescriptionproperty of theServiceHosthas aBehaviorscollection. You can see if a behavior exists by calling theFind<T>()method on the collection. You can add new behaviors by callingAdd()on the collection. Example 1-9 shows an example that looks to see if theServiceMetadataBehaviorexists, and if not adds it to the collection and enables browsing.

    Example 1-9. Adding the metadata service behavior programmatically

    ServiceHost host = new ServiceHost(typeof(HelloIndigo.HelloIndigoService);

    ServiceMetadataBehavior mexBehavior = host.Description.Behaviors. Find<ServiceMetadataBehavior>();

    if (mexBehavior == null)
    {
     
    mexBehavior = new ServiceMetadataBehavior();
     
    mexBehavior.HttpGetEnabled = true;
     
    host.Description.Behaviors.Add(mexBehavior);
    }

    host.Open();

    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

    - 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
    - VBScript: More Fun with the Date Functions
    - Vista Price Cuts Dissected

     
    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 2 hosted by Hostway