A SOAP Client

Fortunately SOAP::Lite means that Perl programmers don't need to worry about generating the XML or negotiating the HTTP transaction. But don't let its name fool you, SOAP::Lite is actually quite a heavyweight program which supports SOAP clients and servers over HTTP(S) (CGI/mod_perl), SMTP, FTP and Jabber. SOAP::Lite even includes XLMRPC::Lite which provides a similar API to make XMLRPC clients and servers.

To create a SOAP client that will generate the request we just looked at you need to know the proxy for the SOAP service, and the URI. The proxy is the actual endpoint address to which requests will go...kind of like that ACTION in a <FORM> tag. When using the HTTP transport mechanism this looks like the familiar URL. The URI uniquely identifies the remote method that is being executed, and when using the HTTP it can often look like a URL (but it's not really).

So here's the client:

     1	#!/usr/bin/perl
     3	use SOAP::Lite;
     5	my $currency = SOAP::Lite->new(
     6	    uri	    => 'urn:xmethods-CurrencyExchange',
     7	    proxy   => 'http://services.xmethods.net/soap',
     8	);
    10	$country1 = SOAP::Data->name( 'country1' => 'US' )->type( 'string' );
    11	$country2 = SOAP::Data->name( 'country2' => 'UK' )->type( 'string' );
    13	$response = $currency->getRate( $country1, $country2 );
    14	print $response->result();