caribesoft has asked for the wisdom of the Perl Monks concerning the following question:

Hi : I have a script that send a SOAP message to a server, I receive back the response via WebService, my quiestion : How can I get the "Response" and convert to Perl Data Structure ? I need to display this info and later insert into a MySql table, can it be possible ? Best regards, Caribesoft ...from Cancun
  • Comment on convert SOAP message to perl data structure

Replies are listed 'Best First'.
Re: convert SOAP message to perl data structure
by Ieronim (Friar) on Jul 11, 2006 at 18:43 UTC
    This is an example script from the SOAP::Lite dooumentation:
    use SOAP::Lite; print SOAP::Lite -> uri('http://www.soaplite.com/Temperatures') -> proxy('http://services.soaplite.com/temper.cgi') -> f2c(32) -> result;
    Here 'Temperatures' is the namespace (url before is ignored), 'http://services.soaplite.com/temper.cgi' is the URL of the remote script, f2c is the name of the method called, 32 is data the method accepts. In this case the data returned by server is one scalar and is converted to perl scalar type on the fly. Usually you know what kind of data the server returns, and many types are automatically converted to Perl data structures.

    At first adapt the example script to fit your needs (all parameters marked italic need to be replaced with your ones!) and try to find out which data is returned from server. Data::Dumper can help you if you have no suggestions about it :) And if you fail, try to ask here a less general question.

Re: convert SOAP message to perl data structure
by mav3067 (Beadle) on Jul 11, 2006 at 17:19 UTC
    Hi caribesoft, Maybe someone else knows exactly, but i need more information if I am going to be able to help you. What kind of data are you getting back in your "Response"? It is possible to get information back from a SOAP::Lite service and put it into a MySQL table. For example:
    #makes the new SOAP::Lite object my $soap_obj = new SOAP::Lite -> uri ('http://') -> proxy ('http://') -> service(); #gets the response and stores it in a scalar my $response = $soap_obj->get_response(); #creates the statement for the SQL insert my $statement = $bdbi->form_push_SQL ($response); #if bdbi is a database connection then it does $statement $bdbi->{'database_handle'}->Query($statement);
    I hope this helps even if it is just a little, and if anyone else has anything to say I would definately take their comments into consideration since I am no expert by any means and this is just a general case that worked for me since you didn't provide much to go on.

      Hi mav3067 :

      Thanks for your help, this is what I get as "Response" :

      <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" +xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance " xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body><consultaUnManifiestoResponse xmlns="http://Recintos/Servic +iosWebXml/"><consultaUnManifiestoResult> <error>0</error> <descripError /><registros>1</registros> <man><nTrans>465</nTrans> <cTransp>HYBU</cTransp> <idTransp>7116834 </idTransp> <nomBuque>ARGOSY</nomBuque> <numViaje>416 SB MEX</numViaje> <fecEstimada>15/12/2004 12:00:00 AM</fecEstimada> <tipoOper>1</tipoOper> <lineaNaviera>NAVIERA VICANE</lineaNaviera> <fecRecibe>14/12/2004 4:09:46 PM</fecRecibe> <cuAduana>53</cuAduana> <cuPais>ATG</cuPais> <cuPuerto>PMS</cuPuerto> <cuEntidadMan>1158</cuEntidadMan> <casos /></man><manifiestos><a nyType xsi:type="ObjManifiesto"> <nTrans>465</nTrans> <cTransp>HYBU</cTransp> <idTransp>7116834 </idTransp> <nomBuque>ARGOSY</nomBuque> <numViaje>416 SB MEX</numViaje> <fecEstimada>15/12/2004 12:00:00 AM</fecEstimada> <tipoOper>1</tipoOper> <lineaNaviera>NAVIERA VICANE</lineaNaviera> <fecRecibe>14/12/2004 4:09:46 PM</fecRecibe> <cuAduana>53</cuAduana> <cuPais>ATG</cuPais><cuPuerto>PMS</cuPuerto> <cuEntidadMan>1158</cuEntidadMan> <casos /></anyType></manifiestos> </consultaUnManifiestoR esult></consultaUnManifiestoResponse></soap:Body></soap:Envelope>

      How can I convert to Perl data structure or insert into a Mysql table ??

      Again, thanks for your help,

      Caribesoft.

      20060712 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips

        Is that really what you are getting back? This doesn't appear to "well formed XML" as there is a closing </anyType> without a corresponding opening one. If it really is what you are getting back then you will need to fix that problem before attempting to process it.

        /J\

Re: convert SOAP message to perl data structure
by philcrow (Priest) on Jul 11, 2006 at 17:45 UTC
    You could use something like SOAP::Lite. On the other hand, SOAP requests and responses are just XML. So, it is also easy to use LWP and XML::Simple.

    Phil

Re: convert SOAP message to perl data structure
by mda2 (Hermit) on Jul 11, 2006 at 22:39 UTC
    Hi,

    The SOAP::Lite module has a call valueof for complex structures. See Other reference.

    Supose this code:

    use strict; use Data::Dumper; my $Call = 'f2c'. my $Result = $soap->call( $Call, 32 ); if ( $Result->fault ) { printf "Failure on call: %s\n\t Code: %s\nString: %s\n\n", $Call, $Result->faultcode, $Result->faultstring; } print Dumper( $Result->valueof('//' . $Call . 'Response') );

    --
    Marco Antonio
    Rio-PM