Here is a quick example of how you would use a SOAP web service to get the conversion rate between currencies using the SOAP web service described here:
The above page describes the method call that is available to you and also provides information about the various currencies available for conversion.
Click the "ConversionRate" method to get more information on how you would call this. This opens a new page (scroll down) with a way to test the web service and a list of the various ways that it can be called.
In the SOAP 1.1 section, you can see that the function is called "ConversionRate" and that it takes two parameters: FromCurrency and ToCurrency, both of which are simply a string containing the currency code.
The last thing to determine is the actual URL to use. Often, web services use the "WSDL" query string to fetch the Web Service Description Language for the service. In the case of this web service, you will use this URL:
With this information, you can use the SOAPMethod class to call the method.
To get started, create a new project and add to the default Window these controls:
- two TextFields to provide the from and to currency codes (FromCurrencyField and ToCurrencyField)
- a PushButton to do the conversion (ConvertButton)
- a TextField to display the results (ConversionRateField)
Now you can put this code in the Action event handler of the PushButton:
Dim sm As New SOAPMethod("http://www.webservicex.net/CurrencyConvertor.asmx?WSDL")
Dim conversionRate As String
conversionRate = sm.ConversionRate(FromCurrencyField.Text, ToCurrencyField.Text)
ConversionRateField.Text = conversionRate
Run the app an enter two currency codes (USD and EUR) and then press the button to get the conversion rate (0.7761 as of today).
There are many public web services that are available for you to use with your apps. Here are two sources of many web services:
Keep in mind that like anything on the web, web services can go offline from time to time so be sure to check for an error condition or invalid result from any web service call.
You can download the sample project (which will be included with Xojo) here.