Calling the getWordsForCheck process now, let's return to the main unit of the Delphi project and then add the import unit in the "Using" list (either by selecting the "File | Using Unit" menu, or by explicitly add it to the "Usage" list Go). In the application main window, we will use three edit boxes, as shown in Figure B. The first edit box (input box) will contain a Arabic number. The second editing box (output box) will contain Use the number of English words. We will use it later in this article, which will contain the same number, but use another language to describe. We use a button to start the event, but we first need one More important components make this all running. Open the WebServices tag in the component palette and drag the first part, HTTPRIO (it represents a remote object that can be accessed by HTTP).
Figure B
Httprio
Do you still remember the URL used when we used the WSDL required to generate the import unit? The import unit simply launched the iWordsForcheck interface and the method of this interface, getWordsforCheck. It did not specify where to find this web service. That is Yes, you need to tell the information of the HTTPRIO component, which is also use WSDL URL. Make sure you don't have any input errors (preferably a simple copy paste), place the WSDL URL in the WSDLLocation property bar of the HTTPRIO component:
http://powerofzen.com/cgi-bin/wordsforchecks.exe/wsdl/iWordsforCheck
Then, open the drop-down list of the service properties and select IWordSforCheckService. Finally, open the drop-down list of port properties iWordsforCheckport (it is also the only option). Now httprio is ready to connect and use web services.
The real use process occurs in the button's onclick event handler. We first need to extract the iWordsforCheck interface from the HTTPRIO component (its effect is to activate the remote web service). Once we gain this interface, we can call it. (In this case, that is the only method getWordsforCheck).
procedure TForm1.Button1Click (Sender: TObject); varWordsForCheck: IWordsForCheck; Number: Integer; beginWordsForCheck: = (HTTPRIO1 AS IWordsForCheck); // connected Number: = StrToInt (Edit1.Text); Edit2.Text: = WordsForCheck.GetWordsForCheck (Number END;
When we enter 42 in the first editing box, then click the button, will form a connection to the remote web service, the iWordSForCheck interface will be extracted (if we can connect to the web service), then the post-number 42 will be converted into " FORTY TWO DOLLARS AND 00 CENTS.
Babelfish
You can also use more than one Web service in a program. For demonstration, let's take a look at the Babelfish translation web service (Altavista Babelfish) how we got the results from English to German. See
XMethods Babelfish Service Details gets more detailed information.
I will use the WSDL URL (http://www.xmethods.net/sd/babelfishservice.wsdl) to generate the import unit and write the WSDL URL to the WSDLLocation property of the other HTTPRIO component to leave you. Don't forget At the same time, set two attributes and port attributes. Then you can add the final code like the following:
procedure TForm1.Button1Click (Sender: TObject); varWordsForCheck: IWordsForCheck; Number: Integer; BabelFish: BabelFishPortType; beginWordsForCheck: = (HTTPRIO1 AS IWordsForCheck); // ConnectNumber: = StrToIntDef (Edit1.Text, 0); Edit2.Text: = Wordsforcheck.GetWordsForcheck (Number); Babelfish: = (httprio2 as babelfishporttype); // connectit3.text: = Babelfish.babelfish ('en_de', edit2.text) End; make it better
Unfortunately, Babelfish service only translated a word in the text. As shown in Figure C, for "Forty TWO", you will get "Vierzig Zwei", it means "forty" and "two" rather than "Forty-two". In order to eliminate this limit, it is also developed English to Dutch translation services (Babelfish has not provided this feature), I decided to write my own Number to Dutch Words (expressed the Netherlands The web service. That will be the topic of our next discussion. At the same time, if you have any questions about using the web service in Delphi 6 or you want to see more examples, please visit when you have time
SOAP section on my web site.
Figure C