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

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 - Proxy Initialization


    (Page 3 of 4 )

    For a client to invoke service operations, it must open a communication channel to a particular service endpoint. This channel is bound to a particular endpoint--its address, binding, and contract. This is done by creating a proxy.

    In the first lab, a proxy is created directly by using the channel factory:

      IHelloIndigoService proxy = 
      ChannelFactory<IHelloIndigoService>. CreateChannel(new BasicHttpBinding(), new
      EndpointAddress("http://localhost:8000/HelloIndigo/ HelloIndigoService"));

    This approach assumes that:

    • You have prior knowledge of the endpoint address.
    • A copy of the service contract definition is locally available.
    • You have prior knowledge of the required protocols or binding configuration.

    If you own both sides (client and service), it is feasible to share an assembly that contains service metadata and to separately communicate the address and binding requirements. When you don't own both sides, generating the proxy is a more effective way to import the metadata necessary to construct the client channel. In this lab, the proxy is generated with SvcUtil. This proxy includes a generated copy of the service contract and a channel wrapper to simplify the client code necessary to consume the service. SvcUtil also generates the service model configuration necessary to initialize the proxy.

    The service contract generated by SvcUtil looks similar to the contract at the service with the exception of additional details specified in theServiceContractAttributeandOperationContractAttribute, shown inExample 1-12 .

    Example 1-12. Service contract generated by SvcUtil

    [System.ServiceModel.ServiceContractAttribute(Namespace= "http://www.thatindigogirl.com/samples/2006/06", ConfigurationName="Client.localhost. IHelloIndigoService")]
    public interface IHelloIndigoService
    {
     
    [System.ServiceModel.OperationContractAttribute(Action=
    "http://www.thatindigogirl.com/samples/2006/ 06/IHelloIndigoService/HelloIndigo", ReplyAction= "http://www.thatindigogirl.com/samples/2006/06
     /IHelloIndigoService/HelloIndigoResponse")]

       string HelloIndigo();
    }

    The namespace specified by theServiceContractAttributeis the same as at the service. This is critical to compatible message serialization.

    The SvcUtil that generated the client-side service contract also generated a proxy type. The proxy type is a partial class that inheritsClientBase<T>from theSystem.ServiceModelnamespace (T is the service contract type). As shown in bold in Example 1-13, the proxy exposes service contract operations and internally uses its reference to the client communication channel to invoke each service operation. In fact, this inner channel reference is like the one you previously created with the channel factory.

    Example 1-13. Proxy type generated by SvcUtil

    public partial class HelloIndigoServiceClient: System.ServiceModel.ClientBase<Client. localhost.IHelloIndigoService>, Client.localhost.IHelloIndigoService
    {
     
    ...overloaded constructors

      public string HelloIndigo()
      {
        return base.Channel.HelloIndigo();
      }
    }

    When the first operation is invoked on this proxy, the inner channel is created based on the endpoint configuration for the proxy. Since in this lab only one endpoint is available, the construction of the proxy looks something like this:

      HelloIndigoServiceClient proxy = new HelloIndigoServiceClient();

    If there are several endpoints to choose from in the<client>configuration section, you are required to provide an endpoint configuration name to the proxy constructor:

      // Proxy construction
      HelloIndigoServiceClient proxy = new HelloIndigoServiceClient("basicHttp");

      // Endpoint configuration
      <endpoint address=http://localhost:8001/HelloIndigo/ HelloIndigoService
      binding="basicHttpBinding" name="basicHttp" contract="Host.IHelloIndigoService" />

    Once the client channel has been used (by invoking an operation), the proxy is bound to the endpoint configuration that initialized it. The same proxy instance cannot be used to invoke another service endpoint, and no changes to protocols or behaviors are allowed. A new proxy (channel) must be constructed if such changes are required.

    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 6 Hosted by Hostway
    Stay green...Green IT