SunQuest
 
       BrainDump
  Home arrow BrainDump arrow Page 4 - Multiple Service Contracts and Indigo
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 
Actuate Whitepapers 
Moblin 
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? 
BRAINDUMP

Multiple Service Contracts and Indigo
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-05-08

    Table of Contents:
  • Multiple Service Contracts and Indigo
  • Hosting two services with multiple contracts
  • Consuming internal services using shared contracts
  • Consuming external services with a generated proxy

  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Multiple Service Contracts and Indigo - Consuming external services with a generated proxy


    (Page 4 of 4 )

    Now you will implement the external client application and invoke service operations over HTTP. In this case, the client will rely on the WSDL document to generate a proxy and related configuration to call the service. This exercise will illustrate how the proxy generation process handles multiple contracts and endpoints.

    1. Start by running theHostproject so that you can generate proxies for each service.
    2. Go to theExternalClientproject in Solution Explorer and add a service reference forServiceA. Provide the base address http://localhost:8000 and name the referenceServiceA. This will generate a proxy for each contract exposed byServiceAand create an application configuration file with client endpoints.
    3. Now add a service reference forServiceB. This time, provide the base address http://localhost:8001 and name the referenceServiceB. This will generate a proxy for each contract exposed byServiceB, adding new client endpoints to the application configuration file.

      The application configuration file is not overwritten when you add new service references. A merge is performed to add to configuration settings. SvcUtil also supports merge through command-line options.
    4. This application will invoke each service using the proxies generated by SvcUtil. Like with theInternalClientapplication, you'll create a proxy reference for each service contract, initialize them in the form constructor, and then close them in theFormClosingevent. The code will be simplified somewhat since the generated proxy hides some of the complexity of creating the communication channel, and directly exposes close functionality. The resulting code is shown in Example 1-25.

      Example 1-25. Code to initialize and close generated proxies for ServiceA and ServiceB

      public partial class Form1 : Form
      {
        ServiceA.ServiceAClient m_proxyA;
        ServiceB.ServiceBClient m_proxyB; 
        public Form1()
        {
          InitializeComponent();

          m_proxyA = new ExternalClient.ServiceA.ServiceAClient("BasicHttpBinding_IServiceA");
          m_proxyB = new ExternalClient.ServiceB.ServiceBClient("BasicHttpBinding_IServiceB");
        }
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
          this.m_proxyA.Close();
          this.m_proxyB.Close();
        }
      }

      You'll notice that each proxy is initialized by passing the name of a particular endpoint from the application configuration file. Each service exposes multiple endpoints, but because this is an Internet client, the assumption is that the
      client won't have permissions to call the TCP nor be able to invoke services over named pipes (named pipes requires same-machine calls). Still, add service reference generated configuration for all endpoints because the WSDL document includes all endpoints for a service.
    5. Now you can add code to invoke each operation. If you look at the form in design view, you'll see that only three buttons are present to invoke the collective operations of both service contracts. Create Click event handlers for each button and add code to invoke each operation through the appropriate proxy. Example 1-26 shows the resulting code.

      Example 1-26. Code to invoke each service operation

      private void button1_Click(object sender, EventArgs e)
      {
        string s = m_proxyA.Operation1();
        MessageBox.Show(s);
      }
      private void button2_Click(object sender, EventArgs e)
      {
        string s = m_proxyA.Operation2();
        MessageBox.Show(s);
      }
      private void button3_Click(object sender, EventArgs e)
      {
        string s = m_proxyB.Operation3();
        MessageBox.Show(s);
      }

    6. Compile and test the external client application. First run theHost, and then runExternalClient. Click each button to invoke the service operations exposed byServiceA andServiceB.

    Let's look at the new concepts and tools introduced in this lab.

    Please check back next week for the conclusion to this article.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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

    - Making Your First Active X Control in Visual...
    - Codes and Packages in Microsoft Project 2007
    - Windows 7: Rumors and Demos
    - XP SP3 Why Me?
    - Breaking Up Your Work in Microsoft Project
    - Breaking Work into Task-Sized Chunks
    - Putting Microsoft`s Worldwide Telescope Unde...
    - Handling Multiple Contracts with Indigo
    - Cleaning Out Your Data in XP
    - 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





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway