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>

In reply to SOAP, WSDL and namespaces by tangent

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.