I don't know squat about SOAP. Now I've been asked to write SOAP servers in Perl (using SOAP::Lite) and having a Python client be able to interact with them. I have a SOAP::Lite server that works just fine. My SOAP::Lite Perl client has no problem calling new() and then making method calls. However, the actual client needs to be written in Python :( My coworker is using ZSI for his Python SOAP client. While my Perl code works, he can't seem to do anything with his Python client.
This is my server code:
#!D:/perl/bin/perl.exe -w use strict; use SOAP::Transport::HTTP; SOAP::Transport::HTTP::CGI -> dispatch_to( 'Temperatures' ) -> handle; package Temperatures; sub f2c { my ( $self, $f, $format ) = @_; my $fmt = $format || $self->{_format}; return sprintf $fmt, (5/9 * ($f - 32)); } sub c2f { my ( $self, $c, $format ) = @_; my $fmt = $format || $self->{_format}; return sprintf $fmt, (32 + $c*9/5); } sub format { my ( $self, $format ) = @_; $self->{_format} = $format if $format; $self->{_format}; } sub new { my $class = shift; bless { _format => '%.2f' }, $class; }
And this is my client (I stripped out the HTML part). Notice that I appear to be instantiating a new Temperature object and then calling methods on it. However, my co-worker cannot do anything with the returned data.
#!D:/perl/bin/perl.exe -wT use strict; use CGI qw/:standard/; use SOAP::Lite +autodispatch => uri => 'http://192.168.1.26/Temperatures', proxy => 'http://192.168.1.26/soap/temper.cgi'; my $temp = param( 'temp' ); my $type = param( 'type' ) || ''; my $format = param( 'format' ) || ''; $temp = '' if ! defined $temp; ($temp) = $temp =~ /([\d.]+)/; ($type) = $type =~ /([cf])/; my $temp_result; if ( $temp ) { my $temperature = Temperatures->new; $temperature->format( $format ) if $format; $temp_result = $type eq 'c' ? $temperature->c2f( $temp ) : $temperature->f2c( $temp ); }
Here's the XML response he gets when he calls new():
<SOAP-ENV:Body> <namesp1:newResponse xmlns:namesp1="http://192.168.1.26/Temperatures +"> <Temperatures xsi:type="namesp1:Temperatures"> <_format xsi:type="xsd:string">%.2f</_format> </Temperatures> </namesp1:newResponse> </SOAP-ENV:Body>
Frankly, I have no idea where to look next. I've done a lot of Web searching, but to no avail. Since I know nothing about SOAP, is it possible that I am just totally misunderstanding the way things work? Is it not possible for a Python client to call a Perl constructor via SOAP? If that's the case, does this mean that the Simple Object Access Protocol isn't really for accessing objects?
Note that if I recode everything in a functional style, Python has no problem communicating with my server.
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
In reply to Using Perl's SOAP::Lite to talk to Python by Ovid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |