I'm currently playing around with accessing a WSDL service (RealOps AMP/BMC RBA for those interested) using SOAP::Lite and need to craft a request in the right format.

I managed to find an old post that almost did what I needed and munged the code into the following:

#!/usr/bin/perl -w use strict; use SOAP::Lite +trace => 'debug', maptype => { }; my $userId = "admin"; my $password = "adminpw"; my $wsdl = "http://10.50.50.132:9080/ws/workflow"; my $gridName = SOAP::Header->name("grid-name" => SOAP::Data->type('' = +> 'SampleGrid1')); my $rba = SOAP::Lite->uri('urn:realops.com:amp:workflow')->proxy($wsdl +); my $wsse = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-ws +security-secext-1.0.xsd"; my $securityHeader = SOAP::Header->name( Security => { UsernameToken => { Username => SOAP::Data->type('' => $userId)->prefix('wsse' +), Password => SOAP::Data->type('' => $password)->prefix('wss +e'), } })->uri($wsse)->prefix('wsse'); my $result = $rba->getAllSOAPServices($gridName, $securityHeader)

This code results in a soap header as follows:

<soap:Header> <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/ +oasis-200401-wss-wssecurity-secext-1.0.xsd"> <UsernameToken> <wsse:Password>adminpw</wsse:Password> <wsse:Username>admin</wsse:Username> </UsernameToken> </wsse:Security> <grid-name>SampleGrid1</grid-name> </soap:Header>

The header needs to look like this:

<soapenv:Header> <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/ +oasis-200401-wss-wssecurity-secext-1.0.xsd"> <wsse:UsernameToken> <wsse:Username>admin</wsse:Username> <wsse:Password>adminpw</wsse:Password> </wsse:UsernameToken> </wsse:Security> <grid-name xmlns="urn:realops.com:amp:workflow">SampleGrid1</grid- +name> </soapenv:Header>

How can I get the "wsse" prefix on the UsernameToken tag? I also need to add the xmlns attribute to grid-name, but I haven't finished RTFMing on that one yet...


In reply to Setting XML prefix for tags with SOAP::Lite by TheFluffyOne

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.