Hello. I am having some difficulty with the XML::Compile::WSDL11 module. I actually have no difficulty running a login operation and obtaining a session token:
use strict; use warnings; use XML::Compile::SOAP11; use XML::Compile::WSDL11; use XML::Compile::Transport::SOAPHTTP; my $wsdl_file = '/home/user/some_wsdl_file.wsdl'; my $wsdl = XML::Compile::WSDL11->new($wsdl_file); $wsdl->importDefinitions('/home/user/schema1.xsd'); $wsdl->importDefinitions('/home/user/schema2.xsd'); $wsdl->importDefinitions('/home/user/schema3.xsd'); my %request = ( Input => { Username => 'username', Password => 'password' } ); my $call = $wsdl->compileClient('LogIn'); my $answer = $call->(%request); my $sessionToken = $answer->{parameters}{Output}{SessionToken};
The SOAP request:
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/env +elope/"> <SOAP-ENV:Body> <tns:LogIn xmlns:tns="http://example.com/tns" xmlns:tns1="http://example.com/tns1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <tns:Input> <tns1:Username>username</tns1:Username> <tns1:Password>password</tns1:Password> </tns:Input> </tns:LogIn> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
This successfully retrieves the session token, as seen in the SOAP response:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Header> <token xmlns="http://example.com/tns">sessiontoken</token> </s:Header> <s:Body> <LogInResponse xmlns="http://example.com/tns"> <Output xmlns:a="http://example.com/tns1" xmlns:i="http://www.w3 +.org/2001/XMLSchema-instance"> <a:SessionToken>sessiontoken</a:SessionToken> </Output> </LogInResponse> </s:Body> </s:Envelope>
The problem I am having is that every other request requires passing this token back. This token needs to be in the SOAP header block. However, I am at a loss as to how to insert anything into the header. For instance, the request to change the password would something like this:
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/env +elope/"> <SOAP-ENV:Header> <tns2:token xmlns="http://example.com/tns">sessiontoken</v2:token> </SOAP-ENV:Header> <SOAP-ENV:Body> <tns:GetNewPassword xmlns:tns="http://example.com/tns" xmlns:tns2="http://example.com/tns2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <tns:Input> <tns2:OldPassword>password</tns2:OldPassword> </tns:Input> </tns:GetNewPassword> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
The key difference being the SOAP-ENV:Header tag. This is the portion I am unable to add. The only way I was ever able to affect the header was trying to use XML::Compile::SOAP::WSS, however this is for an authentication that the API I am trying to access does not use. Any ideas where I am going wrong? I should note there is no header information at all in the WSDL files themselves. Thanks.

In reply to Passing a session token using XML::Compile::WSDL by SeptamusNonovant

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.