2017-06-30 34 views
0

我在使用SOAP :: Lite最基本的示例時遇到了問題。基本SOAP :: Lite用法

最初,我收到了關於版本不匹配的錯誤,所以我按this question添加了soapversion('1.2')

#!/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; 

我不再收到錯誤的版本,而不是我得到:result = $VAR1 = 'Error';

回答

0

我想你想使用一些服務。如果是這樣,你使用proxy方法而不是service。見proxy文檔:

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顯示了一個錯誤:

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

但與FahrenheitToCelsius服務的一般問題。