Windows Scripting
  Home arrow Windows Scripting arrow Page 2 - WCF and Bindings
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 Bindings
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2007-10-04

    Table of Contents:
  • WCF and Bindings
  • Endpoints
  • Binding configuration
  • Metadata Exchange

  • 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 Bindings - Endpoints


    (Page 2 of 4 )

     

    Every service is associated with an address that defines where the service is, a binding that defines how to communicate with the service, and a contract that defines what the service does. This triumvirate governing the service is easy to remember as the ABCof the service. WCF formalizes this relationship in the form of an endpoint. The endpointis the fusion of the address, contract, and binding (see Figure 1-5).


    Figure 1-5.  The endpoint

    Every endpoint must have all three elements, and the host exposes the endpoint. Logically, the endpoint is the service’s interface, and is analogous to a CLR or COM interface. Note in Figure 1-5 the use of the traditional “lollipop” to denote an endpoint.

    Conceptually, even in C# or VB, an interface is an endpoint: the address is the memory address of the type’s virtual table, the binding is CLR JIT compiling, and the contract is the interface itself. Because in classic .NET programming you never deal with addresses or bindings, you take them for granted. In WCF the address and the binding are not ordained, and need to be configured.

    Every service must expose at least one business endpoint and each endpoint has exactly one contract. All endpoints on a service have unique addresses, and a single service can expose multiple endpoints. These endpoints can use the same or different bindings and can expose the same or different contracts. There is absolutely no relationship between the various endpoints a service provides.

    It is important to point out that nothing in the service code pertains to its endpoints and they are always external to the service code. You can configure endpoints either administratively using a config file or programmatically.

    Administrative Endpoint Configuration

    Configuring an endpoint administratively requires placing the endpoints in the hosting process’ config file. For example, given this service definition:

      namespace MyNamespace
      {
        
    [ServiceContract]
         interface IMyContract
         {...}
         class MyService : IMyContract
         {...}
     
    }

    Example 1-6 shows the required entries in the config file. Under each service type you list its endpoints.

    Example 1-6. Administrative endpoint configuration

    <system.serviceModel>
       <services>
          <service name = "MyNamespace.MyService">
            
    <endpoint
                address  = http://localhost:8000/MyService/
                binding  = "wsHttpBinding" 
                contract = "MyNamespace.IMyContract"
             />
          </service>
       </services>
    </system.serviceModel>

    When you specify the service and the contract type, you need to use fully qualified type names. I will omit the namespace in the examples throughout the remainder of this book, but you should use a namespace when applicable. Note that if the endpoint provides a base address, then that address schema must be consistent with the binding, such as HTTP withWSHttpBinding. A mismatch causes an exception at the service load time.

    Example 1-7 shows a config file defining a single service that exposes multiple endpoints. You can configure multiple endpoints with the same base address as long as the URI is different.

    Example 1-7. Multiple endpoints on the same service

    <service name  = "MyService">
      
    <endpoint
           address  = http://localhost:8000/MyService/
           binding  = "wsHttpBinding"
           contract = "IMyContract"
      
    />
       <endpoint
           address  = "net.tcp://localhost:8001/MyService/"
           binding  = "netTcpBinding"
           contract = "IMyContract"
      
    />
       <endpoint
           address  = "net.tcp://localhost:8002/MyService/"
           binding  = "netTcpBinding"
           contract = "IMyOtherContract"
      
    />
    </service>

    Administrative configuration is the option of choice in the majority of cases because it provides the flexibility to change the service address, binding, and even exposed contracts without rebuilding and redeploying the service.

    Using base addresses

    In Example 1-7, each endpoint provided its own base address. When you provide an explicit base address, it overrides any base address the host may have provided.

    You can also have multiple endpoints use the same base address, as long as the endpoint addresses differ in their URIs:

      <service name  = "MyService">
         <endpoint
            address  = "net.tcp://localhost:8001/MyService/"
            binding  = "netTcpBinding"
            contract = "IMyContract"
         />
        
    <endpoint
            address  = "net.tcp://localhost:8001/MyOtherService/"
            binding  = "netTcpBinding"
            contract = "IMyContract"
         />
      </service>

    Alternatively, if the host provides a base address with a matching transport schema, you can leave the address out, in which case the endpoint address will be the same as the base address of the matching transport:

      <endpoint
         binding  = "wsHttpBinding"
         contract = "IMyContract"
     
    />

    If the host does not provide a matching base address, loading the service host will fail with an exception.

    When you configure the endpoint address you can add just the relative URI under the base address:

      <endpoint
         address  = "SubAddress"
         binding  = "wsHttpBinding"
         contract = "IMyContract"
     
    />

    The endpoint address in this case will be the matching base address plus the URI, and, again, the host must provide a matching base address.

    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 Lowry (O'Reilly, 2007; ISBN: 0596526997). Check it out 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 5 hosted by Hostway
    Stay green...Green IT