Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

SOAP, WSDL and namespaces

by tangent (Parson)
on Mar 10, 2016 at 16:53 UTC ( [id://1157322]=perlquestion: print w/replies, xml ) Need Help??

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

Venerable Monks,
I am trying to call a web service using SOAP with a WSDL using either XML::Compile or SOAP::Lite...

Using XML::Compile

my $soap_wdsl = 'example.wsdl'; # retrieved previously my $client = XML::Compile::WSDL11->new( $soap_wdsl ); my $call = $client->compileClient('setTransaction'); my $response = $call->( $params ); <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Body> <tns:setTransaction xmlns:tns="http://soap.example.com/" xmlns:xsi +="http://www.w3.org/2001/XMLSchema-instance"> <PARAMS HERE> </tns:setTransaction> </SOAP-ENV:Body>
This works fine, but I have to add security headers which are not defined in the WSDL - you can see a solution at the FAQ but I can't work out how to implement it. Has anyone managed to use this example?

Now I can add headers easily enough with SOAP::Lite, but I have a problem with that too.

Using SOAP::Lite

my $soap_wdsl = 'https://example.com/service/API?wsdl'; my $client = SOAP::Lite->new; $client->proxy( $soap_wdsl ); $client->service( $soap_wdsl ); my $response = $client->setTransaction( $params ); <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Body> <setTransaction> <PARAMS HERE> </setTransaction> </SOAP-ENV:Body>
This doesn't work because it is not setting the namespace in the setTransaction tag. I found a solution by adding this line:
$client->ns('http://soap.example.com/'); <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:namesp1="http://soap.example.com/"> <SOAP-ENV:Body> <namesp1:setTransaction> <PARAMS HERE> </namesp1:setTransaction> </SOAP-ENV:Body>
But I don't want to hard code the URL as I feel that defeats the purpose of the WSDL - what if it changes down the line? Is there a way to retrieve that namespace URL from the WSDL so I can add it dynamically? Or some other way to get SOAP::Lite to add it properly?

Just for reference, I have a PHP example which works properly (and no issues adding headers):

$soap_wdsl = 'https://example.com/service/API?wsdl'; $client = new SoapClient( $soap_wdsl ); $response = $client->setTransaction( $params ); <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://soap.example.com/"> <SOAP-ENV:Body> <ns1:setTransaction> <PARAMS HERE> </ns1:setTransaction> </SOAP-ENV:Body>

Replies are listed 'Best First'.
Re: SOAP, WSDL and namespaces
by Anonymous Monk on Mar 11, 2016 at 00:28 UTC

    This works fine, but I have to add security headers which are not defined in the WSDL - you can see a solution at the FAQ but I can't work out how to implement it. Has anyone managed to use this example?

    :D the author, obviously :P See XML::Compile::SOAP::WSS

    But I don't want to hard code the URL as I feel that defeats the purpose of the WSDL - what if it changes down the line?

    Things change, life goes on, adapt/improvise/overcome...

    Is there a way to retrieve that namespace URL from the WSDL so I can add it dynamically?

    Sure, its just xml, but see next part

    Or some other way to get SOAP::Lite to add it properly?

    It depends heavily on the part you're leaving out, the part most folks like me know little about, even SOAP::Lite, the WSDL

    See https://metacpan.org/pod/SOAP::Lite#BUGS-AND-LIMITATIONS

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1157322]
Approved by stevieb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-23 20:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found