Delphi-Kylix
  Home arrow Delphi-Kylix arrow Page 3 - Creating a Web Service Client with Delphi
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
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? 
DELPHI-KYLIX

Creating a Web Service Client with Delphi
By: Leidago
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 11
    2006-10-30

    Table of Contents:
  • Creating a Web Service Client with Delphi
  • Code Listing
  • The application
  • Behind the scenes

  • 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


    Creating a Web Service Client with Delphi - The application


    (Page 3 of 4 )

    Create a new application and add a memo, a button (caption it Check Weather), and an edit box. Go to the web services tab and drop an HTTPRIO component . Save this application in the same directory where you’ve saved the unit created earlier. In the implementation section of the form add the following - uses WeatherForecast;

    Your form should now look something like this at design time:

    The HTTPRIO component represents a remote invokable object over an HTTP connection. What this means is that our client will use this component to communicate with the web service over the Internet. The component has four key properties:

    • URL
    • Service
    • WSDLLocation
    • Port

    Of these properties, you either use the URL property or the WSDLLocation, Service and Port  properties. So let's fill these these properties as follows:

    WSDLLocation - http://www.webservicex.net/WeatherForecast.asmx?WSDL

    Service - WeatherForecast

    Port – WeatherForecastSoap

    Most of these properties will already have information available to them when you click on the dropdown boxes. The HTTPRIO component will now contain all the methods of the web service.

    Next, double click on the button and add the following code:

    procedure TForm1.Button1Click(Sender: TObject);
    var
    wf:WeatherForecastS;
    res:ArrayOfWeatherData;
    i:integer;
    begin
    wf:=(htt as WeatherForecastSoap).GetWeatherByPlaceName
    (edit1.Text);
    if wf.PlaceName<> '' then
    res:=wf.Details;
    memo1.Lines.Add('The min and max temps in Fahrenheit is:');
    memo1.Lines.Add(' ');
    for i:= 0 to high(res) do
    begin
    memo1.Lines.Add(res[i].Day+'   -   '+ ' Max Temp. Fahr: '+res
    [i].MaxTemperatureF+'   -   '+'Min Temp Fahr: '+res
    [i].MinTemperatureF);
    end
    end;

    The code first takes the city name and then retrieves the weather data:

    wf:=(htt as WeatherForecastSoap).GetWeatherByPlaceName
    (edit1.Text);
    if wf.PlaceName<> '' then
    res:=wf.Details;
    memo1.Lines.Add('The min and max temps in Fahrenheit is:');
    memo1.Lines.Add(' ');

    Then it simply loops through the results that are stored in the array and adds them to the memo:

    for i:= 0 to high(res) do
    begin
    memo1.Lines.Add(res[i].Day+'   -   '+ ' Max Temp. Fahr: '+res
    [i].MaxTemperatureF+'   -   '+'Min Temp Fahr: '+res
    [i].MinTemperatureF);

    Below is a screen shot of a test run of the application:

    More Delphi-Kylix Articles
    More By Leidago


       · In this article i explain how to create a webservice client with Delphi.
     

    DELPHI-KYLIX ARTICLES

    - Delphi Wrapper Classes and XML
    - Delphi and the DOM
    - Delphi and XML
    - Internet Access: Client Service
    - Finishing the Client for an Internet Access ...
    - The Client for an Internet Access Control Ap...
    - User Management for an Internet Access Contr...
    - Important Procedures for an Internet Access ...
    - Server Code for an Internet Access Control A...
    - Constructing the Interface for an Internet A...
    - Building a Server Application for an Interne...
    - Building an Internet Access Control Applicat...
    - Client Dataset: Working with Data Packets an...
    - Using the Client Dataset in an N-Tiered Appl...
    - Using the Client Dataset in Two-Tiered Clien...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT