Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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

by SeptamusNonovant (Novice)
on Dec 17, 2013 at 21:19 UTC ( #1067533=note: print w/replies, xml ) Need Help??

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

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.

Replies are listed 'Best First'.
Re^3: Passing a session token using XML::Compile::WSDL
by runrig (Abbot) on Dec 17, 2013 at 23:35 UTC
      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://1067533]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2017-01-16 11:18 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (149 votes). Check out past polls.