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

    Table of Contents:
  • WCF and Proxies
  • Programmatic Client Configuration
  • WCF Architecture
  • The InProcFactory Class
  • Binding and Reliability
  • Requiring Ordered Delivery

  • 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 Proxies - Programmatic Client Configuration


    (Page 2 of 6 )

    Instead of relying on a config file, the client can programmatically construct address and binding objects matching the service endpoint and provide them to the proxy constructor. There is no need to provide the contract, since that was provided in the form of the generic type parameter of the proxy. To represent the address, the client needs to instantiate an EndpointAddress class, defined as:

      public class EndpointAddress
      {
         public EndpointAddress(string uri);
         //More members
     
    }

    Example 1-20 demonstrates this technique, showing the code equivalent to Example 1-16 targeting the service in Example 1-9.

    Example 1-20. Programmatic client configuration

    Binding wsBinding = new WSHttpBinding(); EndpointAddress endpointAddress = new
                         
    EndpointAddress("http://localhost:8000/MyService/");

    MyContractClient proxy = new MyContractClient(wsBinding,endpointAddress);

    proxy.MyMethod();
    proxy.Close();

    Similar to using a binding section in a config file, the client can programmatically configure the binding properties:

      WSHttpBinding wsBinding = new WSHttpBinding();
      wsBinding.SendTimeout = TimeSpan.FromMinutes(5);
      wsBinding.TransactionFlow = true;

      EndpointAddress endpointAddress = new
                           EndpointAddress("http://localhost:8000/MyService/");

      MyContractClient proxy = new MyContractClient(wsBinding,endpointAddress);
      proxy.MyMethod();
      proxy.Close();

    Again, note the use of the concrete subclass ofBindingin order to access binding-specific properties such as the transaction flow.

    Programmatic Versus Administrative Configuration

    The two techniques shown so far for configuring both the client and service complement each other. Administrative configuration gives you the option to change major aspects of the service and the client post-deployment, without even the need to rebuild or redeploy. The major downside of administrative configuration is that it is not type-safe, and configuration errors will only be discovered at runtime.

    Programmatic configuration is useful when the configuration decision is either completely dynamic—when it is taken at runtime based on the current input or conditions—or when the decision is static and never changes, in which case you might as well hardcode it. For example, if you are interested in hosting in-proc calls only, you might as well hardcode the use of theNetNamedPipeBindingand its configuration. However, by and large, most clients and services do resort to using a config file.

    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 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 2 hosted by Hostway
    Stay green...Green IT