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

Hello!

I'm looking for an example of a Perl SOAP client that can communicate with a Java service. I've been researching it all day and I can't make mine work. Has anyone had success in communicating with Java services?

Thanks!

P.S. I did post this to SitePoint, but there have been no replies for 5-6 hours, so now here's your chance to show 'em up!

Some people are like Slinkies. Not really good for anything, but you still can't help but smile when you see one tumble down the stairs.

Replies are listed 'Best First'.
Re: Perl, SOAP and Java
by cengineer (Pilgrim) on May 24, 2007 at 22:15 UTC
    I used stubmaker to create a perl module with the available soap calls:
    stubmaker http://www.website.com/service?WSDL
    Put this perl module in /etc/perl or whereever you put your perl modules for inclusion on your system. The code is pretty basic. Read the contents of a file that you want to post to the service. Post it. Get the response. Print the response..
    use strict; use warnings; use MySOAPService qw(:all); # Data file my $dataFile = "/path/to/dataToPost.xml"; # Open our input file open(INFILE, $dataFile) or die "Could not open $dataFile: $!\n"; # Set our variable to read contents of our input file my $postData = do { local $/; <INFILE> }; # Close our input file close(INFILE); # Get a response from the post data my $response = soapCallFromWSDLModule($postData); print "Response from server: $response\n";
    Hope this helps!
Re: Perl, SOAP and Java
by lin0 (Curate) on May 24, 2007 at 21:44 UTC

    Hi darkwater23,

    You could have a look at:

    Ask the magic eight ball: In this article, Doug Tidwell takes a simple piece of Java code, deploys it as a Web service, and writes a few clients for it.

    Cheers,

    lin0

      Ok, update for all!

      I found the problem. The SOAP response contains an element named 'xmlStr'. The Perl module dies because this is invalid, according to the XML spec. The author of the module suggested that one could comment out lines 1084 and 1085 in the Lite.pm file, though it was not recommended. This allowed processing of the response to continue.

      My test script ended up not needing the SOAP::WSDL part. A boiled down version looks like this:

      use SOAP::Lite; my $result = SOAP::Lite -> service('http://cms-test.pmic.com/startquote/form/RateCalculation +sService.wsdl') ->getQuote('<passed in the xml doc containing the parameters for the + request as a string>'); $result =~ m~<TOTALMODALPREMIUM>(.+?)</TOTALMODALPREMIUM>~ig; my $quote = $1;

      I hope this helps someone else!

      Some people are like Slinkies. Not really good for anything, but you still can't help but smile when you see one tumble down the stairs.