I am trying to set the body of a SOAP request to a given string (the data may come from a file, for example), but I am getting an extra tag that is causing my call to error at the server. Basically, I want Soap Lite (or another library) to let me fill in EXACTLY what goes between <soap:Body> and </soap:Body> Here is the test code:
#!/usr/bin/perl use SOAP::Lite +trace; my ($server, $endpoint, $soapaction, $method, $body, $envelope); $server = 'http://127.0.0.1'; $endpoint = "$server/Just_Some_Test"; $soapaction = "Just_Some_Test"; # This will eventually come from a file $body = qq~<wsap:GetData soapenv:encodingStyle="http://schemas.xmlsoap +.org/soap/encoding/"> <Just_A_String> </Just_A_String> </wsap:GetData> ~; # Set the envelope - Will eventually contain other specific stuff my $envelope = SOAP::Serializer->new(); $envelope-> register_ns ("http://www.w3.org/2001/XMLSchema-instance", +"xsi"); $envelope-> register_ns ("http://www.w3.org/2001/XMLSchema", "xsd"); # Initialize the object my $getData = SOAP::Lite -> serializer ($envelope) -> uri ($soapaction) -> readable (1) -> proxy ($endpoint) -> on_fault(sub { my($soap, $res) = @_; die ref $res ? "ERROR " . $res->faultdetail : "ERROR +" .$soap->transport->status, "\n"; }) ; # Make the call and set the Body of the message my $response = $getData->call( method => SOAP::Data->type(xml => $body +) ); if ( $response->fault ) { printf "***A fault (%s) occurred: %s\n", $response->faultcode, $response->faultstring; } else { print "***Response: " . $response->result . "\n"; } exit;
The above code produces the following:
<?xml version="1.0" encoding="UTF-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <method xmlns="Just_Some_Test"> <wsap:GetData soapenv:encodingStyle="http://schemas.xmlsoap.org/ +soap/encoding/"> <Just_A_String> </Just_A_String> </wsap:GetData> </method> </soap:Body> </soap:Envelope>
I've looked at some of the threads on setting the body to raw XML, but there always seems to be some extra tags left over. The above is almost perfect! I just need to get rid of:
<method xmlns="Just_Some_Test">
and it's closing tag. Can this be done?

In reply to SOAP? Setting BODY Manually by marcjb

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.