Creating a Client to an External Web Service In this lesson, you will learn how to create a Delphi web client application to communicate with an external Web Service. 
A major repository of available Web Services is located at http://www.xmethods.net. This site is dedicated to publishing publicly available Web Services for interoperability testing during development. By scrolling through the available Web Services on XMethods, you will notice the different tools and platforms used to develop those services. There are a variety of solutions presented including stock quote watchers, language translators, courier tracking and mathematical engines. Browse the Web Service Information Develop a client for AltaVista's Babel Fish Web Service for text translation. 
1. In a web browser, navigate to http://www.xmethods.net and click the Babel Fish Web Service. 
2. Examine the Service Details page for information about the Babel Fish Web Service, its endpoints and method names. Also notice the path to the WSDL file for the service: http://www.xmethods.net/sd/2001/BabelFishService.wsdl. Creating a Simple Client User Interface Create a simple client user interface. 
1. From Delphi, choose File | New | Application. 
2. From the Standard Component Palette, add two Memo components, and one Button component to the Form Designer. 
3. In the Component Palette, click the WebServices tab and then add an HTTPRIO component to the form. Importing the WSDL File into Delphi Import the Babel Fish WSDL file into Delphi, which will generate a Pascal wrapper around the file. 
1. Choose File | New | Other. 
2. In the New Items dialog box, select the Web Services tab, and then open the Web Services Importer. 
3. In the WSDL or XML Schema Location text box, enter the path to the BabelFish WSDL file (http://www.xmethods.net/sd/2001/BabelFishService.wsdl) and then click Generate. Notice how Delphi generates a Pascal file that wraps the BabelFish service and its methods in the code editor. 
4. Now add the generated unit name of the imported service description to the uses clause of your main application form. Setting the HTTPRIO Properties Set the properties of the HTTPRIO component. 
1. In the design environment, click the HTTPRIO component and then set the WSDLLocation property to the Babel Fish WSDL path. http://www.xmethods.net/sd/2001/BabelFishService.wsdl 
2. Set the Service property to BabelFishService. 
3. Set the Port property to BabelFishPort. The client application is now ready to call into the BabelFish Web Service.Adding the event handler to the Button Tip: In Try It mode, double-click 01_code.txt in the sample files frame to open it. Add the event handler to the button. 
1. Copy and paste the following code from the provided text file to the OnClick event Handler for the Button on your main form: 
procedure TForm1.Button1Click(Sender: TObject); 
var BabelService: BabelFishPortType; 
begin 
  BabelService:= HTTPRio1 as BabelFishPortType; 
  memo2.Text :=  BabelService.BabelFish('en_fr', memo1.text); 
end; 
This code will allow for the translation of any text input in the Memo1 component, translate it from English to French and display the result in the Memo2 component. 
The first parameter passed to the BabelFish function is the translation mode to specify the languages used to perform the translation. Running the Client Application Compile and Run the application. 
1. Click Project | Compile Project and then click Run. 
2. In the first Memo component enter hello world. 
3. Click the Button. The Memo 2 component shows the translated string in the French language. 
Delphi's HTTPRIO component is the key to making it simple to create a client to a Web Service. HTTPRIO generates statically-linked calls to invokable interfaces on a remote Web Service application. When an application casts HTTPRIO to a registered invokable interface, it dynamically generates an in-memory method table, providing an implementation to that invokable interface. HTTPRIO executes the methods in this table by encoding the method call as a SOAP request and sending an HTTP request message to the Web Service application. It unpacks the resulting HTTP response message to obtain the return value and any output parameters, or to raise an exception if the request generated an exception on the server. 
In this lesson, you have learned how to create a Delphi web client application to communicate with an external Web Service.