Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

SOAP::Lite, WSDLs and Raw XML Data

by Ozeroc (Novice)
on Jun 12, 2008 at 09:21 UTC ( #691616=perlquestion: print w/replies, xml ) Need Help??
Ozeroc has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to send raw XML to a wsdl service using SOAP::Lite.
Here's the relevant portion of my code:
use SOAP::Lite +trace => 'debug'; my $wsurl = ''; my $svc = SOAP::Lite-> service($wsurl); $svc-> InsertData(@temparray);
This works BUT the angle brackets are getting escaped because the data type is set to string. To fix this I attempted to use SOAP::Data to set the type to XML like so:
use SOAP::Lite +trace => 'debug'; my $wsurl = ''; my $svc = SOAP::Lite-> service($wsurl); my @xmldata = SOAP::Data->type('xml' => @temparray); $svc-> InsertData(@xmldata);
This results in an empty call to the service (no data). If I examine the resulting @xmldata with Data::Dumper I can see the data like so:
$VAR1 = bless( { '_type' => 'xml', '_signature' => [], '_value' => [ '<?xml version="1.0" encoding="UTF-8"?> +', '<Data1>', '<Data2>', etc... ], '_attr' => {} }, 'SOAP::Data' );
I'm pretty new at this web services stuff and I'd like to think that perl can do anything that Java/XMLSpy can do, but this is getting frustrating. I get the same results whether I sent the xml as an array or a long string.
Any help sending raw xml to a web service would be greatly appreciated. Thanks monks! Rob

Replies are listed 'Best First'.
Re: SOAP::Lite, WSDLs and Raw XML Data
by Anonymous Monk on Jun 12, 2008 at 10:16 UTC
    I don't know much about xml, but I don't think you can have a <?xml version="1.0" encoding="UTF-8"?> in the middle of a document.
Re: SOAP::Lite, WSDLs and Raw XML Data
by Anonymous Monk on Jun 12, 2008 at 11:03 UTC
    Here's an example adopted from
    #!/usr/bin/perl -- # adopted from # perl -MSOAP::Lite=debug -S +amples.cgi getStateList([1,9]) use warnings; use strict; use SOAP::Lite; use Data::Dumper; $Data::Dumper::Terse = 1; $Data::Dumper::Indent = 1; use SOAP::Lite +trace => 'debug'; @ARGV = qw[ ]; my ( $proxy, $uri ) = ( shift, shift ); my $soap = SOAP::Lite->proxy($proxy)->on_fault( sub { } ); $soap->uri($uri) if $uri; $soap->readable(1); # lifesaver my $raw_xml = q~<soapenc:Array soapenc:arrayType="xsd:int[2]" xsi:type="soapenc:Ar +ray"> <item xsi:type="xsd:int">1</item> <item xsi:type="xsd:int">9</item> </soapenc:Array>~; my $res = $soap->getStateList( SOAP::Data->type( 'xml' => $raw_xml ) ) +; #my $res = $soap->getStateList([1,9]); die join "\n", "--- SOAP FAULT ---", $res->faultcode, $res->faultstrin +g, '' if defined($res) && $res->fault; die join "\n", "--- TRANSPORT ERROR ---", $soap->transport->status, '' if !$soap->transport->is_success; print STDERR join "\n", "--- SOAP RESULT ---", Dumper( $res->paramsall + ), ''; __END__ SOAP::Transport::HTTP::Client::send_receive: POST http://services.soap HTTP/1.1 Accept: text/xml Accept: multipart/* Accept: application/soap Content-Length: 668 Content-Type: text/xml; charset=utf-8 SOAPAction: "" <?xml version="1.0" encoding="UTF-8"?> <soap:Envelope xmlns:xsi="" xmlns:soapenc="" xmlns:xsd="" soap:encodingStyle="" xmlns:soap=""> <soap:Body> <getStateList xmlns=""> <s +oapenc:Array soapenc:arrayType="xsd:int[2]" xsi:type="soapenc:Array"> <item xsi:type="xsd:int">1</item> <item xsi:type="xsd:int">9</item> </soapenc:Array> </getStateList> </soap:Body> </soap:Envelope> SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 200 OK Connection: close Date: Thu, 12 Jun 2008 10:54:40 GMT Server: Apache/1.3.37 (Unix) mod_throttle/3.1.2 DAV/1.0.3 mod_fastcgi/ +2.4.2 mod_gzip/ PHP/4.4.8 mod_ssl/2.8.22 OpenSSL/0.9.7e Content-Length: 683 Content-Type: text/xml; charset=utf-8 Client-Date: Thu, 12 Jun 2008 10:58:23 GMT Client-Peer: Client-Response-Num: 1 SOAPServer: SOAP::Lite/Perl/0.55 <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:xsi="ht +tp://" xmlns:SOAP-ENC="http://schem" xmlns:SOAP-ENV="http://schemas.xmlsoap" xmlns:xsd="" SOA +P-ENV:encodingStyle=""><SOAP +-ENV:Body><namesp1:getStateListResponse xmlns:namesp1="http://www.soa"><SOAP-ENC:Array xsi:type="SOAP-ENC:Array" SOAP +-ENC:arrayType="xsd:string[2]"><item xsi:type="xsd:string">Alabama</i +tem><item xsi:type="xsd:string">Florida</item></SOAP-ENC:Array></name +sp1:getStateListResponse></SOAP-ENV:Body></SOAP-ENV:Envelope> --- SOAP RESULT --- [ 'Alabama', 'Florida' ]

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://691616]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2018-05-25 09:35 GMT
Find Nodes?
    Voting Booth?