Adding an authHeader request to Perl SOAP :: Lite

I am having trouble making a request to this WSDL that works; this requires authHeaders, and I was not very lucky to add them. This is what I am trying:


# make proxy for the service
my $soap = SOAP::Lite->service($wsdl);

# add fault hanlder
$soap->on_fault(

    sub { # SOAP fault handler
        my $soap = shift;
        my $res = shift;

        # Map faults to exceptions
        if(ref($res) eq '') {
            die($res);
        }
        else {
            die($res->faultstring);
        }

        return new SOAP::SOM;
    }

);

# authentication request headers
my @headers = (
    SOAP::Header->name('user')->value('myemail@whatever.com')->uri($apins),
    SOAP::Header->name('password')->value('mypassword')->uri($apins),
    SOAP::Header->name('appName')->value('TestApp')->uri($apins),
    SOAP::Header->name('appVersion')->value('0.02')->uri($apins)
);

# request method
print $soap->getCompanyInfo('NB', @headers);

The answer I get with this is:

Expected String Value Instead of SOAP :: Header Link

The method I'm requesting has two string parameters, both optional. And suggestions?

+3
source share
1 answer

I managed to get help on the SOAP :: Lite mailing list. If I want to pass my own headers, I have to use a call method instead of a method name.


# create header for requests 
my $authHeader = SOAP::Header->name("xsd:authHeader" => 
\SOAP::Header->value(
    SOAP::Header->name('xsd:user')->value($s7user)->type(''),
    SOAP::Header->name('xsd:password')->value($s7pass)->type(''),
    SOAP::Header->name('xsd:appName')->value('TestApp')->type(''),
    SOAP::Header->name('xsd:appVersion')->value('0.03')->type('')
));

# create data to pass as method paramaters
my $params = SOAP::Data->name('ns:email')->value($s7user)->type('');

# request method
$soap->call('checkLogin', $params, $authHeader);

To use the call method, you will need to define a proxy (endpoint) on your soap object. Hope this helps someone else along the way.

+6

Source: https://habr.com/ru/post/1785247/


All Articles