Home arrow Delphi-Kylix arrow Page 3 - Creating a Web Service Client with Delphi
DELPHI-KYLIX

Creating a Web Service Client with Delphi


In this article, the second of three parts covering web services, we will build a web service client and discuss the various components and methods needed to make an application work.

Author Info:
By: Leidago
Rating: 5 stars5 stars5 stars5 stars5 stars / 26
October 30, 2006
TABLE OF CONTENTS:
  1. · Creating a Web Service Client with Delphi
  2. · Code Listing
  3. · The application
  4. · Behind the scenes

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

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:


blog comments powered by Disqus
DELPHI-KYLIX ARTICLES

- Loading an XML Document into the DOM
- 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...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials