I have an application (IPControl) that uses Soap/WSDL for an API. In order to access that API I first have to send an "init" message and from the response to that, get the session ID out of the response. That session ID is needed for future message for that request.

To make it even more complicated, it uses a "multiref" response with other stuff in the response, rather than just "sesionid=xxx"

Here's an example of a response to the initial message:

<?xml version="1.0" encoding="utf-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/e +nvelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="htt +p://www.w3.org/2001/XMLSchema-instance"> <soapenv:Header> <ns1:sessionID soapenv:actor="http://schemas.xmlsoap.org/s +oap/actor/next" soapenv:mustUnderstand="0" href="#id0" xmlns:ns1="htt +p://xml.apache.org/axis/session"/> </soapenv:Header> <soapenv:Body> <ns2:initExportDeviceResponse soapenv:encodingStyle="http: +//schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://diamondip.com +/netcontrol/ws/"> <initExportDeviceReturn href="#id1"/> </ns2:initExportDeviceResponse> <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle= +"http://schemas.xmlsoap.org/soap/encoding/" xsi:type="soapenc:long" x +mlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">-91025392591 +2285490</multiRef> <multiRef id="id1" soapenc:root="0" soapenv:encodingStyle= +"http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns3:WSContext" +xmlns:ns3="http://service.ipcontrol.diamondip.com" xmlns:soapenc="htt +p://schemas.xmlsoap.org/soap/encoding/"> <contextId xsi:type="soapenc:string">ContextId_1364228 +178892</contextId> <contextType xsi:type="soapenc:string">Export_Device</ +contextType> <filter xsi:type="soapenc:string">DeviceType='NAS'</fi +lter> <firstResultPos href="#id2"/> <internalResultCount href="#id3"/> <maxResults href="#id4"/> <options xsi:type="soapenc:string" xsi:nil="true"/> <query xsi:type="soapenc:string">SELECT DISTINCT huge- +ass sql statement cropped for clarity) ) ) ) ) ORDER BY 1</query> <resultCount href="#id5"/> </multiRef> <multiRef id="id4" soapenc:root="0" soapenv:encodingStyle= +"http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns: +soapenc="http://schemas.xmlsoap.org/soap/encoding/">5000</multiRef> <multiRef id="id3" soapenc:root="0" soapenv:encodingStyle= +"http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns: +soapenc="http://schemas.xmlsoap.org/soap/encoding/">0</multiRef> <multiRef id="id5" soapenc:root="0" soapenv:encodingStyle= +"http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns: +soapenc="http://schemas.xmlsoap.org/soap/encoding/">152</multiRef> <multiRef id="id2" soapenc:root="0" soapenv:encodingStyle= +"http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns: +soapenc="http://schemas.xmlsoap.org/soap/encoding/">0</multiRef> </soapenv:Body> </soapenv:Envelope>

Most of that is junk for verification, but I included in case it adds complications. The only thing I really want to pull out that message is the "ns1:sessionID" which has the value of multiRef id="id0"

Here's what I have for a bare-minimum script right now:

## USE THESE use strict; use warnings; use SOAP::Lite; use Data::Dumper; ## AUTHENTICATION my $user = 'username'; my $pass = 'password'; sub SOAP::Transport::HTTP::Client::get_basic_credentials { return $use +r => $pass; } ## WSDL AND FILTER DEFINIATION my $WSDL = 'http://localhost:8080/inc-ws/services/Exports?wsdl'; my $filter = "DeviceType='NAS'"; ## MAKE THE CALL, PRINT THE RESULTS my $client = SOAP::Lite ->service($WSDL); my $result = $client->initExportDevice($filter); print Dumper($result);
I get the results just fine (filter, resultcount, maxresults, etc) when I print the $result. Just not sure how to get access to that value that was in the header.

In reply to SOAP::Lite Client - Read response header by sojourner9

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.