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

Maybe I'm just too "new" in this realm and it hasn't hit me yet, but here's my potential problem.

In a client, written in Perl, I can create an object using the new method on my class (written in Perl) and stuff variables into that object to my hearts content. The I can call a method within the class, passing the object to the method. That's great. Because, imho, both sides (client and server) are written in Perl.

#!/usr/bin/perl -w use SOAP::Lite; my $soap = SOAP::Lite -> uri('DocPub') -> proxy('http://10.7.2.33:2738/cgi-bin/soap/docpub.pl'); my $t = $soap -> call(new => '') -> result; $t->{name} = "Thomas"; my $r = $soap->hi($t); print $r->result;
Or somesuch similar to the above. If a client is written in Java, or (eek)VB, can they handle creating an object with the new method, and doing what I did above in Perl? (I don't program much outside of Perl, SQL and a bit of other random stuff..)

Should I pass parameters to the method via an array?
$r = $soap->hi($param1,$param2,$param3);

Should I datatype the variables first?
my $v = SOAP::Data->type('string')->name(uid => 'Thomas'); my $name = $v->value;
Server stays the same:
sub hi { my $self = shift; my $e = shift; return "Hello $e"; }
Of course, I want to change the method hi() to use it's params by name and not simply shifting off an array. (Who's to say they are in the right order?)

I guess the "big" question is this: How to I pass variables to a method by name, and be sure the server can handle requests from multiple clients, written in different languages?

I've read up on the various texts out there. (The guide on soaplite.com was a tremendous help..) So I've come to the belief that I'm simply overlooking, or looking too hard

Thanks so much,

_14k4 - perlmonks@poorheart.com (www.poorheart.com)

Replies are listed 'Best First'.
Re: SOAP and multiple client platforms
by one4k4 (Hermit) on Jun 13, 2002 at 14:39 UTC
    Here's a possible solution that "seems" to work for me:
    sub hi { my $self = shift; my %args = (@_); my ($name,$age) = (@_); my $byname = 0; foreach my $needed (qw(age name)) { $byname=1 if $args{$needed}; } if ($byname) { $name = $args{name}; $age = $args{age}; } return "Name: $name Age: $age"; }
    The idea was pretty much copied from http://groups.yahoo.com/group/soaplite/message/230.

    _14k4 - perlmonks@poorheart.com (www.poorheart.com)
Re: SOAP and multiple client platforms
by samtregar (Abbot) on Jun 13, 2002 at 16:39 UTC
    Have you tried posting to the SOAP::Lite mailing-list? I've found the people there, including Paul Kulchenko the author of SOAP::Lite, exceedingly knowledgable and helpful.

    Just to add my two cents though: the only way you're going to know if a given SOAP technique works in multiple toolkits is by trying it. I suggest you bust out some baby Java and give it a try.

    -sam

Re: SOAP and multiple client platforms
by cmilfo (Hermit) on Jun 13, 2002 at 21:01 UTC
    I've only used SOAP::Lite on one project. An instance of the monitoring tool we wrote is installed on each server. The monitoring tool is written in Perl and uses SOAP::Transport::HTTP, acting as the SOAP server. There is one multi-threaded beast written in Java. This Java program requests from each of the monitoring tools statistics, files, etc.

    All communication is over HTTPS (which is a bear to debug). Might I add that we did initial development over HTTP. A good packet sniffer will help a lot; Ethereal was our *most* valuable development tool! And, I might add that if you plan to send *any* binary data at all, use MIME::Base64 to encode it first (we used Digest::MD5 to checksum to data before encoding it -- the encoding algorithm checks but just in case).

    The big idea with SOAP is to pass a familiar data structure to the SOAP library, which serializes and sends the data. Now, the other party should receive the data and deserialize it into a data structure the program can understand.

    We never successfully got the Java program to send its requests as HashTables, but we did get the Java program to receive the data as a HashTable (sent from Perl as a hash, received by Java as a HashTable).

    That was our experience. Some of what I read on the soaplite news group mentioned above was that certain data structures are still kind of fuzzy. Now, what was meant by that (i.e. Perl's SOAP library is at fault vs. Java's SOAP library is at fault), I don't know. But, if I remember correctly, when Perl deserialized the Java request (sent as a HashTable) it came out as an array.

    Just some of my experiences.
    Casey
      I've got things working with the code snippet above, and I'm onto a new "problem":
      my $soap_request = <<END; POST /insuranceClaims HTTP/1.1 Host: 10.7.2.33 Content-Type: Multipart/Related; boundary=MIME_boundary; type=text/xml +; start="<cid:foo4\@bar.net>" Content-Length: 1024 SOAPAction: http://10.7.2.33:2738/Hello Content-Description: This is the optional message description. --MIME_boundary Content-Type: text/xml; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-ID: <cid:foo4\@bar.net> Content-Location: http://10.7.2.33:2738/Hello <?xml version='1.0' ?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/env +elope/"> <SOAP-ENV:Body> <ns1:hi> <upload_file href="http://10.7.2.33:2738/upload_file.txt"/> <name>Thomas</name> </ns1:hi> </SOAP-ENV:Body> </SOAP-ENV:Envelope> --MIME_boundary Content-Type: text/xml; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-ID: <http://10.7.2.33:2738/upload_file.txt> Content-Location :http://10.7.2.33:2738/upload_file.txt ...binary TIFF image... --MIME_boundary-- END
      This time I'm not using SOAP::Lite because of it's lack for multipart MIME messages/Attachments. What that has done, is helped me learn a lot more about this stuff. ;)

      It's just that now SOAP replies with "Cannot find 'start' parameter in multipart MIME message". Bah.

      if (!$one_thing){$it=$another";}

      _14k4 - perlmonks@poorheart.com (www.poorheart.com)