The SOAP request: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};
This successfully retrieves the session token, as seen in the SOAP response:<?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>
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:<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 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.<?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>
In reply to Passing a session token using XML::Compile::WSDL by SeptamusNonovant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |