Hello all
I'm attempting to write up some examples for a tutorial / quickstart
guide and am currently deriving examples of clients for doc/lit style
services. Here's the first example:
use SOAP::Lite +trace;
use strict;
my $uri = 'http://www.webserviceX.NET';
my $url = 'http://www.webservicex.net/globalweather.asmx';
my $client = SOAP::Lite
-> uri($uri)
-> on_action( sub { join '/', $uri, $_[1] } )
-> proxy($url)
-> autotype(0)
-> readable(1);
my $args = { CityName => 'Cambridge',
CountryName => 'United Kingdom',
};
$client->GetWeather($args)->attr({xmlns => $uri});
However, the XML this sends to the service is thus:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetWeather xmlns="http://www.webserviceX.NET">
<c-gensym3>
<CountryName>United Kingdom</CountryName>
<CityName>Cambridge</CityName>
</c-gensym3>
</GetWeather>
</soap:Body>
</soap:Envelope>
Note the c-gensym3 wrapper around my arguments, which causes the
request to fail. I get around this with this:
use SOAP::Lite +trace;
use strict;
my $uri = 'http://www.webserviceX.NET';
my $url = 'http://www.webservicex.net/globalweather.asmx';
my $client = SOAP::Lite
-> uri($uri)
-> on_action( sub { join '/', $uri, $_[1] } )
-> proxy($url)
-> autotype(0)
-> readable(1);
my $args = { CityName => 'Cambridge',
CountryName => 'United Kingdom',
};
my $data = handroll($args);
$client->GetWeather($data)->attr({xmlns => $uri});
sub handroll {
my $hash = shift;
my @array;
while(my($key,$value) = each %$hash) {
push @array, SOAP::Data->name($key)->value($value);
}
return \@array;
}
Which produces the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetWeather xmlns="http://www.webserviceX.NET">
<CountryName>United Kingdom</CountryName>
<CityName>Cambridge</CityName>
</GetWeather>
</soap:Body>
</soap:Envelope>
Note now there is no c-gensym wrapper, and the service accepts the
request and returns my results as expected (try it, it's a valid
working service). The question I have is: is there a more elegant way
to avoid the c-gensym wrapper and, if not, might it be a good idea to
add such a way to S::L?
Cheers
Robbie
|