Windows Scripting
  Home arrow Windows Scripting arrow Page 3 - WCF and Hosting
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? 
WINDOWS SCRIPTING

WCF and Hosting
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2007-09-27

    Table of Contents:
  • WCF and Hosting
  • Self-Hosting
  • Advanced hosting features
  • Bindings

  • 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


    WCF and Hosting - Advanced hosting features


    (Page 3 of 4 )

    The ICommunicationObject interface supported by ServiceHostoffers some advanced features, listed in Example 1-4.

    Example 1-4. The ICommunicationObject interface

    public interface ICommunicationObject
    {
      
    void Open();
      
    void Close();
      
    void Abort();

       event EventHandler Closed;
      
    event EventHandler Closing;
      
    event EventHandler Faulted;
      
    event EventHandler Opened;
      
    event EventHandler Opening;

       IAsyncResult BeginClose(AsyncCallback callback,object state);
       IAsyncResult BeginOpen(AsyncCallback callback,object state);
       void EndClose(IAsyncResult result);
       void EndOpen(IAsyncResult result);

       CommunicationState State
      
    {get;}
     
    //More members
    }
    public enum CommunicationState
    {
      
    Created,
      
    Opening,
      
    Opened,
      
    Closing,
      
    Closed,
      
    Faulted
    }

    If opening or closing the host is a lengthy operation, you can do so asynchronously with theBeginOpen()andBeginClose()methods. You can subscribe to hosting events such as state changes or faults, and you can use theStateproperty to query for the host status. Finally, theServiceHostclass also implements theAbort()method.Abort()is an ungraceful exit—when called, it immediately aborts all service calls in progress and shuts down the host. Active clients will get an exception.

    The ServiceHost<T> class

    You can improve on the WCF-provided ServiceHost class by defining the ServiceHost<T>class, as shown in Example 1-5.

    Example 1-5. The ServiceHost<T> class

    public class ServiceHost<T> : ServiceHost
    {
      
    public ServiceHost() : base(typeof(T))
      
    {}
      
    public ServiceHost(params string[] baseAddresses) :
                                   
    base(typeof(T),Convert(baseAddresses))
       {}
       public ServiceHost(params Uri[] baseAddresses) : 
                   
    base(typeof(T),baseAddresses)
       {}
      
    static Uri[] Convert(string[] baseAddresses)
      
    {
         
    Converter<string,Uri> convert = delegate(string address)
                       {
                          return new Uri(address);
                       };
          return Array.ConvertAll(baseAddresses,convert);
       }
    }

    ServiceHost<T>provides simple constructors that do not require the service type as a construction parameter, and can operate on raw strings instead of the cumbersomeUri. I’ll add quite a few extensions, features, and capabilities toServiceHost<T>in the rest of the book.

    WAS Hosting

    The Windows Activation Service (WAS) is a system service available with Windows Vista. WAS is part of IIS7, but can be installed and configured separately. To use the WAS for hosting your WCF service, you need to supply a .svcfile, just as with IIS. The main difference between IIS and WAS is that the WAS is not limited to HTTP and can be used with any of the available WCF transports, ports, and queues.

    WAS offers many advantages over self-hosting, including application pooling, recycling, idle time management, identity management, and isolation, and is the host process of choice when available; that is, when you can target either a Vista Server machine for scalability or a Vista client machine used as a server machine for a handful of clients only.

    Still, the self-hosted process offers singular advantages such as in-proc hosting, dealing with unknown customer environments, and easy programmatic access to the advanced hosting features described previously.

    More Windows Scripting Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Programming WCF Services," published by...
     

    Buy this book now. This article is excerpted from chapter one of Programming WCF Services, written by Juval Lowy (O'Reilly, 2007; ISBN: 0596526997). Check it out today at your favorite bookstore. Buy this book now.

    WINDOWS SCRIPTING ARTICLES

    - Introducing Two-Way Data Binding using Silve...
    - Silverlight 2.0 Application Development with...
    - Burning Multisession CDs with IMAPI2 in WSH
    - Creating a Silverlight 2.0 Application that ...
    - Burning CDs with the IMAPI2 Control
    - Burning CDs in Windows XP with WSH
    - Advanced Word Object Scripting
    - Reading and Printing Word Documents in WSH
    - Scripting Microsoft Word
    - Using WSH to Catalog MP3 Files
    - Reading MP3 ID3 Tags in WSH
    - A Brief Look at Menus in WPF
    - More Examples of Simplified Image Processing...
    - Completing a WPF To-Do List Application
    - Simplified Image Processing in GDI+





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