in reply to Re: Setting XML prefix for tags with SOAP::Lite
in thread Setting XML prefix for tags with SOAP::Lite

With the SOAP call in better shape, I had to work around an issue with the Username and Password being in the wrong order (the WSDL specifies them as a sequence).

I think I just have one more hurdle to overcome. The current version of the script results in the SOAP body:

<soap:Body> <DirList xmlns="Test_Module" xsi:nil="true" /> </soap:Body>

But in order to work it seems that it should be:

<soap:Body> <tra:DirList /> </soap:Body>

(Where tra is a namespace defined as "Test_Module"). Additionally, I'll want to add a couple of parameters like so:

<soap:Body> <tra:DirList> <param1>value1</param1> <param2>value2</param2> </tra:DirList> </soap:Body>

My recent attempts at adding the parameters have resulted in lots of c-gensym tags added, which I think is an indication that I'm not referencing the data correctly

The code as it currently stands (without the attempt at adding parameters):

#!/usr/bin/perl -w use strict; use SOAP::Lite +trace => 'debug', maptype => { }; use Tie::IxHash; my $userId = "admin"; my $password = "adminpw"; my %authHash; tie %authHash, "Tie::IxHash"; %authHash = ( Username => SOAP::Data->type( '' => $userId )->prefix('wss +e'), Password => SOAP::Data->type( '' => $password )->prefix('w +sse'), ); my $wsdl = "http://10.50.50.132:9080/ws/workflow"; my $rba = SOAP::Lite->uri('Test_Module')->proxy($wsdl); $rba->on_action(sub { return '"execute-workflow"'; } ); my $wsse = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-ws +security-secext-1.0.xsd"; my $gridName = SOAP::Header->new( name => 'grid-name', value => 'Amsterdam', uri => 'urn:realops.com:amp:workflow', prefix => '', type => '', ); my $securityHeader = SOAP::Header->new( name => 'Security', uri => $wsse, prefix => 'wsse', value => \SOAP::Data->new( name => 'UsernameToken', prefix => 'wsse', value => \%authHash ) ); my $result = $rba->DirList($gridName, $securityHeader)->result(); print "\n\n\n$result\n";

Replies are listed 'Best First'.
Re^3: Setting XML prefix for tags with SOAP::Lite
by TheFluffyOne (Beadle) on Jul 31, 2008 at 21:56 UTC

    Well as I was cleaning up my parameter-adding code to post, I had some inspiration and have found a way to do it (though it seems clunky). I have also realised that it wasn't the lack of prefix causing the problem, it was that I was using the wrong method name (d'oh!). New code:

    my @params = ( SOAP::Data->new( prefix => '', name => 'param1', value => SOAP::Data->type('' =>'value1') ), SOAP::Data->new( prefix => '', name => 'param2', value => SOAP::Data->type('' =>'value2') ) ); my $result = $rba->DirList(@params, $gridName, $securityHeader)->resul +t();

    Which results in:

    <soap:Body> <DirList xmlns="Test_Module"> <param1>value1</param1> <param2>value2</param2> </DirList> </soap:Body>

    The tag "DirList" needs to be "DirList-Request", but I can't use this directly in my current code as I get bareword errors...

      Well after much more RTFMing and Googling, I've figured out how to handle the hyphenated method name:

      my $result = $rba->call($workflowName => (@params, $gridName, $securityHeader))->result();

      This code isn't a direct replacement for the line in the code above as I have reworked a few variables, but I think knowing that $workflowName is the method name to call should be enough for most to figure it out :)

      Next challenge is to figure out why 'result' isn't being populated...