rjx5 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I am trying to make simple API call (at least that's what I thought initially when I started ) using SOAP::Lite module. I am using one of the publicly available SOAP API here to add two numbers. I am getting following error:
Server did not recognize the value of HTTP Header SOAPAction: http://t +empuri.org/#Add.
I enabled the debug in SOAP::Lite and it seems my request is not formed correctly. I suspect the type specified (xsi:type="xsd:int") in intA and intB is causing issue or the # sign in the SOAPAction (I couldnt find out why and where this is added to the uri) Request from debug:
<?xml version="1.0" encoding="UTF-8"?> <soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soap:Body> <Add xmlns="http://tempuri.org/"> <intA xsi:type="xsd:int">5</intA> <intB xsi:type="xsd:int">10</intB> </Add> </soap:Body> </soap:Envelope>
Here is my Perl code:
#!/usr/bin/env perl use strict; use warnings; use SOAP::Lite; #use SOAP::Lite +trace => 'all'; SOAP::Lite->import(trace => 'debug'); #my $uri = 'http://tempuri.org/'; my $proxy = 'http://www.dneonline.com/calculator.asmx'; my $ns = 'http://tempuri.org/'; my $client = SOAP::Lite ->readable(1) ->uri($ns) ->proxy($proxy); my $param1 = SOAP::Data->name("intA" => $x); my $param2 = SOAP::Data->name("intB" => $y); my $response = $client->Add($param1,$param2); print "Result is $response \n";
Note: I tried loading the WSDL in SOAPUI tool and the API works fine there.

Replies are listed 'Best First'.
Re: Error calling a simple Soap API using Perl's Soap::Lite
by poj (Abbot) on Oct 10, 2018 at 12:41 UTC
    or the # sign in the SOAPAction (I couldnt find out why and where this is added to the uri)

    See on_action(callback) in SOAP::Lite. Try adding

    $client->on_action( sub { join '', @_ } );
    poj
      Thanks poj, that helps. I overlooked the on_action method. Final code looks like this:
      my $proxy = 'http://www.dneonline.com/calculator.asmx'; my $ns = 'http://www.tempuri.org/'; $method = SOAP::Data->name('Add') ->attr({xmlns => 'http://tempuri.org/'}); $client = SOAP::Lite->new() ->proxy($proxy) ->ns($ns,'tem') ->readable(1); $client->on_action( sub { join '', @_ } ); push(@parms, SOAP::Data->name(intA => $x)); push(@parms, SOAP::Data->name(intB => $y)); $response = $client->call($method => @parms)->result; print "Result is $response \n";