Basic SOAP::Lite usage

203 views Asked by At

I'm having trouble using the most basic example of SOAP::Lite.

Initially, I was getting an error about version mismatch, so I added the soapversion('1.2') as per this question.

#!/usr/bin/perl -w
use strict;
use SOAP::Lite;
use Data::Dumper;

my $service = SOAP::Lite->service('https://www.w3schools.com/xml/tempconvert.asmx?WSDL');
$service->soapversion('1.2');
$service->serializer->soapversion('1.2');
my $result = $service->FahrenheitToCelsius('212');
print "result = " . Dumper $result;

I no longer get version error, instead I get: result = $VAR1 = 'Error';

1

There are 1 answers

0
palik On

I suppose you want to use some service. If so you use use proxy method instead of service. See proxy documentation:

The proxy is the server or endpoint to which the client is going to connect. This method allows the setting of the endpoint, along with any extra information that the transport object may need when communicating the request.

This method is actually an alias to the proxy method of SOAP::Transport

f2c.pl

#!/usr/bin/perl -w
use strict;

# tracing for debugging purposes
# use SOAP::Lite +trace => "debug";
use SOAP::Lite;
use Data::Dumper;

my $service
    = SOAP::Lite->proxy('https://www.w3schools.com/xml/tempconvert.asmx?WSDL')
    # use on_action cb to override default SOAPAction value
    ->on_action(
    sub {
        return join '/', "https://www.w3schools.com/xml", $_[1];
    }
    );
my $result = $service->FahrenheitToCelsius('212');

# result is an instance of SOAP::SOM
# see https://metacpan.org/pod/distribution/SOAP-Lite/lib/SOAP/SOM.pod
$result->fault && die $result->faultstring;
print "result = " . Dumper $result->body;

perl f2c.pl shows an error:

result = $VAR1 = {
          'FahrenheitToCelsiusResponse' => {
                                           'FahrenheitToCelsiusResult' => 'Error'
                                         }
        };

But there is a general issue with FahrenheitToCelsius service.