Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Trouble getting started with SOAP (SOAP::Lite, SOAP::WSDL), translating from PHP to Perl

by Anonymous Monk
on Feb 20, 2012 at 16:24 UTC ( #955091=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to get started writing a SOAP client, and it is proving difficult for two reasons. 1) The only working example I have for the SOAP sever I need to use is written in PHP, and it uses complex data types. 2) I don't have a SOAP server that I can use to test the Perl code I need to write.

I am having trouble finding the perl equivalent of the following PHP code

$soap = new SoapClient("https://the.soap.url/api/service?wsdl", array("classmap"=>array("Type1"=>"Type1", "Type2"=>"Type2")));

The class definitions look similar to the following:

class Type1 { var $f11 = null; var $f12 = null; } class Type2 { var $f21 = null; var $f22 = null; var $f23 = null; }

The following perl code fails, I assume because it contains no information about the expected classes

my $soap = SOAP::Lite->service('https://the.soap.url/api/service/?wsdl');

And to make it more challenging, I have not had the need to write my own Perl classes (though I write Java and C++ classes all the time, so the main ideas are not new to me).

I can read PHP well enough to understand what it is doing, but I have not written any of my own PHP code.

Far be it from me to recommend anything MS, but I found that the documentation they provid for their Visual Studio has a neat educational feature. For .NET, they have extensive examples, and you can select the langauge (VB, C#, &c.) at the top of the examples, so you can see how to do a given task in each fo the supported languages. This is a great help if you want to learn the langages well enough to translate code from one language to another. Can anyone recommend a site that facilitates seeing how PHP and Perl relate to each other (not so much an ontological relation, but rather how each does any given task).

As always, any guidance would be greatly appreciated.

Comment on Trouble getting started with SOAP (SOAP::Lite, SOAP::WSDL), translating from PHP to Perl
Select or Download Code
Re: Trouble getting started with SOAP (SOAP::Lite, SOAP::WSDL), translating from PHP to Perl
by Khen1950fx (Canon) on Feb 20, 2012 at 19:09 UTC
    I don't do PHP, but I can help you to get started with SOAP::WSDL. Here's an example that gets the current weather for KSFO(San Francisco):
    #!/usr/bin/perl use strict; use warnings; use SOAP::WSDL; my $soap = SOAP::WSDL->new(); my $som = $soap->wsdl( "http://www.webservicex.net/GlobalWeather.asmx?WSDL") -> call('GetWeather', GetWeather => { CountryName => 'United States', CityName => 'San Francisco' } ); print $som->result(), "\n";

      Thanks Khen1950fx

      It is nice to have one example that works.

      Do you have a working example for a cgi server?

      SOAP itself looks to be simple enough, looking like a variant of XML (which for me is quite familiar). But, it is the communication between the client and server which doesn't seem so simple. For example, it looks like the core problem I have with the WSDL file for which I have the URL, appears to be the use of complex data types. It is clear to me that the call I quoted from the working PHP script has created definitions of two classes, and that the second argument to SOAPClient is some kind of array with pointers or a map to the class definitions. I have not found anything that is obviously similar to that in Perl's various SOAP packages. Suppose I wanted to create a server and a client that handled peronal IDs and addresses, and started by creating a person class and an address class (with the peerson class having an address as a data member). How would I create the server to both receive such data and how would I write the client so that it knows about these classes? I don't know PHP that well, but I assume my perl SOAP client would not be able to connect to the server unless it includes the class definitions when it first tries to connect (mimicing what the PHP code seems to do). But then, the question is, how do I do that?

        Can you show more of the PHP code (ugh) - does it reference those classes anywhere else? I'm assuming you can't acquire the specification for the 'https://the.soap.url/api/'?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2014-11-23 11:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (131 votes), past polls