Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Passing a session token using XML::Compile::WSDL

by runrig (Abbot)
on Dec 17, 2013 at 00:30 UTC ( #1067396=note: print w/replies, xml ) Need Help??

in reply to Passing a session token using XML::Compile::WSDL

I've got this as part of my SOAP calling code. Pass in the credentials under a 'Header' key:
my $tmp = $f->( Header => $self->{CREDENTIALS}, @_ );
The full generic method I use to compile SOAP operations is here (but no credentials used in that example).

Replies are listed 'Best First'.
Re^2: Passing a session token using XML::Compile::WSDL
by SeptamusNonovant (Novice) on Dec 17, 2013 at 21:19 UTC
    Thank you. This has started me on the right track, but I'm still not quite there yet. The parameter appears to be 'header' with a lowercase 'h'. But it seems like it only accepts an arrayref containing a hashref. I tried looking through the modules themselves as well as the documentation to see how to structure this and eventually I came to this:
    my $header = [{ parts => [{ name => 'token', element => 'tns:token', destination => $sessionToken, mustUnderstand => 1 }] }];
    This structure got me the farthest (I was either getting errors about it not being a hashref or arrayref, or a "panic: findName called without name" before). But now I'm getting this error:
    error: cannot find element or attribute `{}token +'
    That despite when I do the login and do a dumper on the $answer variable I get this:
    Answer: $VAR1 = { 'parameters' => { 'Output' => { 'SessionToken' => 'sessiontokenv +alue' } }, '{}token' => bless( do{\(my $o = 44800 +400)}, 'XML::LibXML::Element' ) };
    Yet when I try to add that into the header with that same namespace, it complains it can't find the element. Now I tried making a schema just for this token (since it is not defined in any of the WSDLs or XSDs that the company whose API I am trying to access provides):
    <?xml version="1.0" encoding="utf-8"?> <xs:schema elementFormDefault="qualified" targetNamespace="" xmlns:xs="" xmlns:tns=""> <xs:element name="token" nillable="true" type="xs:string" /> </xs:schema>
    Now I get a different error: Can't call method "header" on unblessed reference at /usr/local/perl/5.16.1/lib/site_perl/5.16.1/XML/Compile/Transport/ line 340. So now it wants the header to be an object, and it appears the default value comes from HTTP::Headers (which is not the kind of header I want, I'm looking for the SOAP envelope header tag. So how do I build the header element? Thanks.
        I saw that, but I found it very difficult to follow. I've been trying to figure out how to use that to add the header I need to my request SOAP envelope, but I have not been successful, nor have I found any working examples in my various searches on this topic.
        So I used WSA as a reference and made the INPUT and OUTPUT the same for addHeader. It seems to have taken this time:
        my $ns = ''; my $op = $wsdl->operation(...); $op->addHeader(INPUT => "tns_token" => "{$ns}token"); $op->addHeader(OUTPUT => "tns_token" => "{$ns}token"); $call = $op->compileClient(token => $sessionToken);
        I got no complaints about token not being found. However, I still am not getting any header information in the SOAP envelope. Am I still missing something?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1067396]
and the monks are mute...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2018-06-21 05:03 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.