Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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).


Comment on Re: Passing a session token using XML::Compile::WSDL
Download Code
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 `{http://example.com/tns}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' } }, '{http://example.com/tns}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="http://example.com/tns" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://example.com/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/SOAPHTTP.pm 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 = 'http://example.com/tns'; 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1067396]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (11)
As of 2014-10-24 18:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (134 votes), past polls