Creating HTML and Windows Clients for Web Services (Part 3 of 4) (cont.)

Create a Windows Client
Unfortunately, you have to create yet another new project to test the Web service from a Windows Forms client. A Mobile Web Form project will not accommodate Windows application form controls.

Here's an alternative (and easier) way to create the proxy objects with Visual Studio .NET that eliminates the complexities of command line utilities and introduces a GUI interface you can use to create proxy objects.

  1. Create a new C# project in Visual Studio .NET (New -> Project -> Visual C# Project -> Windows Application
  2. Name the project "Stocks_WinApp"
  3. After creating the project, right-click on the References item in the Solutions Explorer window and select "Add Web Reference" from the context menu. You'll see the Add Web Reference Wizard.
  4. To add a Web reference you need to select the Web service's WSDL file. (Alternatively, you could select the disco file for some Web services.) Enter the WSDL file location of the Delayed Stock Service into the "Address" combo box and then click the "Green arrow" icon next to it (see Figure 3). Visual Studio tries to communicate with the Web service. If it can establish communication, the Wizard displays the service's WSDL file in the left pane. When you see the WSDL file contents, click the "Add Reference" button at the bottom of the Wizard screen.
  5. Visual Studio .NET then tries to create and add a proxy object class to your project. VS.NET performs the whole proxy object creation process in the background. The Add Web Reference Wizard is much more efficient than the wsdl.exe command-line utility described in the previous article in this series.
  6. Create the Windows Form by dragging and dropping toolbox controls onto the form designer. When you're done, the form should look like Figure 4.
  7. Finally, you need to add the code for "Get Quote" and "New Quote" buttons.
Before you can do that, you need to create a "Proxy Object" so you can call the Web service, but you don't yet know what the class name or any method names are. To find the class name you can look at the "Class View" of the Solutions Explorer. (Switch between the tabs of "Solutions Explorer") Your "Class View" will look similar to Figure 5.

By examining the "Class View" you can see the class hierarchy of the proxy object to see the names of the class itself and its public methods. In this case, the full name of the proxy object class type is net.xmethods.services.netxmethodsservicesstockquoteStockQuoteService

Now that you know the correct names, you can add the code for the two buttons.

   private void Btn_Get_Quote_Click(object sender, 
      System.EventArgs e)
   {
      net.xmethods.services.
        netxmethodsservicesstockquoteStockQuoteService 
        proxyClass = new 
        net.xmethods.services.
        netxmethodsservicesstockquoteStockQuoteService();
      try
      {
         if (proxyClass.getQuote(Txt_Code.Text).
            ToString() != "-1")
            Lbl_Price.Text = "Price :- $" + 
            proxyClass.getQuote
            Txt_Code.Text).ToString();
          else
            Lbl_Price.Text = 
            "Price :- Stock code not found";
      }
      catch
      {
         Lbl_Price.Text = "Stock code not found";
      }
   
   }
   
   private void Btn_New_Quote_Click(object sender, 
      System.EventArgs e)
   {
      Lbl_Price.Text = "Price :- ";
      Txt_Code.Text = "";
   }
  1. Finally, build and run the application. The results look like Figure 6.
At this point in the article series, you've seen examples of all the Web services clients. You can develop a Pocket PC client using .NET CE version using code similar to the code in these examples. This is the penultimate article of the series. The next and final article will discuss more advanced Web services topics, such as security, transaction support, creating .NET Remoting Web services, and UDDI.


Chris Peiris designs and develops scalable, high-performance MS Web solutions for financial institutions and media groups. He publishes articles frequently and recently co-authored the book "C# Web Service with .NET Remoting and ASP.NET" for Wrox Press. He lectures on Distributed Object Models (.NET,CORBA & J2EE) at Monash University, Caulfield, Victoria, Australia. He can be reached at http://www.chrispeiris.com.


Create an HTML Client

Back to the Beginning

Ways to Consume Web Services using HTTP Create an HTML Client Create a Windows Client


 






 TALK BACK
What are you using to create web pages to consume XML Web Services? Are you simultaneously building WAP and Windows clients? Are you using Java to build Web services as well as .NET?
Click here to Join
Article 1 in this Series

Article 2 in this Series

Microsoft Downloads—.NET Framework

Java GLUE Implementation

Book Price Comparison Web Service

Download the Stock Clients Project Code





 
Sponsored Links

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map
Jupiterweb networks

internet.comearthweb.comDevx.comClickZ

Search Jupiterweb:

Jupitermedia Corporation has four divisions:
JupiterWeb, JupiterResearch, JupiterEvents, and JupiterImages

Copyright 2004 Jupitermedia Corporation All Rights Reserved.
Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Jupitermedia Corporate Info | Newsletters | Tech Jobs | E-mail Offers

Copyright Information/Privacy Statement