Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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 = 'http://xxxxxxxx.com/SVC/services/Service?wsdl'; 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 = 'http://xxxxxxxx.com/SVC/services/Service?wsdl'; 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

Comment on SOAP::Lite, WSDLs and Raw XML Data
Select or Download Code
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 SOAPsh.pl
    #!/usr/bin/perl -- # adopted from # perl -MSOAP::Lite=debug -S SOAPsh.pl http://services.soaplite.com/ex +amples.cgi http://www.soaplite.com/My/Examples 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[ http://services.soaplite.com/examples.cgi http://www.soaplite.com/My/Examples ]; 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 +lite.com/examples.cgi HTTP/1.1 Accept: text/xml Accept: multipart/* Accept: application/soap Content-Length: 668 Content-Type: text/xml; charset=utf-8 SOAPAction: "http://www.soaplite.com/My/Examples#getStateList" <?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> <getStateList xmlns="http://www.soaplite.com/My/Examples"> <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/1.3.26.1a 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: 208.113.208.191:80 Client-Response-Num: 1 SOAPServer: SOAP::Lite/Perl/0.55 <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:xsi="ht +tp://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schem +as.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap +.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" SOA +P-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP +-ENV:Body><namesp1:getStateListResponse xmlns:namesp1="http://www.soa +plite.com/My/Examples"><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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2015-07-02 05:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (29 votes), past polls