Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Suppressing nil attribute in empty SOAP tag

by ptum (Priest)
on Oct 12, 2011 at 22:24 UTC ( #931103=perlquestion: print w/ replies, xml ) Need Help??
ptum has asked for the wisdom of the Perl Monks concerning the following question:

I'm using SOAP::Lite in a client which consumes a SOAP service over which I have no control. Traditionally, I've used code like this:

my $response; eval { $response = $soap_handle->call('MyMethod', $security_token, $datagra +m); }}; if ($@) { print "Error: SOAP call died: $@. \n"; }

When the method doesn't call for any arguments, I just pass undef in $datagram, and it worked just fine, producing XML like this:

<?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope blah blah blah> <soapenv:Header> <wsse:Security blah><blah>blah</blah></wsse:Security> </soapenv:Header> <soapenv:Body> <MyMethod xsi:nil="true" /> </soapenv:Body> </soapenv:Envelope>

Recently, the vendor has updated their web service, and they no longer accept the xsi:nil="true" attribute.

How can I suppress that nil attribute using SOAP::Lite, so that my tag looks more like this?

<soapenv:Body> <MyMethod/> </soapenv:Body>

No good deed goes unpunished. -- (attributed to) Oscar Wilde

Comment on Suppressing nil attribute in empty SOAP tag
Select or Download Code
Re: Suppressing nil attribute in empty SOAP tag
by Anonymous Monk on Oct 13, 2011 at 03:45 UTC
Re: Suppressing nil attribute in empty SOAP tag
by gnork (Scribe) on Mar 14, 2012 at 15:06 UTC
    I stumbled over the same problem a few days ago and found a possible solution.

    Here is a snippet from my post to the SOAP::Lite Mailinglist.

    --snip--
    All I found so far on the web is the hint to create my own serializer to solve this.

    I dont think this will solve my problem as I dont want to change the behaviour of SOAP::Lite with regard to serialization of an undefined parameter
    but rather want to skip the parameter serialization for parameterless method calls completely.

    After some UTSL I changed line 1593 in SOAP::Lite from

    $body->set_value($parameters ? \$parameters : SOAP::Utils::encode_data()) if $body;

    to

    $body->set_value($parameters, \$parameters) if $body && $parameters;

    which results in the "correct" body tag as described above.

    I would like to know if there is a better way to achieve this or if not,whether we could make this behaviour configuration dependend lets say over a
    method call like $handle->suppress_nils_in_parameterless_calls(1|0) as already implemented for calls like $handle->use_default_ns()
    --/snip--

    cat /dev/world | perl -e "(/(^.*? \?) 42\!/) && (print $1))"
    errors->(c)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2014-12-28 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (183 votes), past polls