tangent has asked for the wisdom of the Perl Monks concerning the following question:
Using XML::Compile
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?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>
Now I can add headers easily enough with SOAP::Lite, but I have a problem with that too.
Using SOAP::Lite
This doesn't work because it is not setting the namespace in the setTransaction tag. I found a solution by adding this line: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>
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?$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>
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 |