I'm trying to make a SOAP request from javascript using AJAX, thus getting my feet wet with two technologies and one programming language at the same time :^). I'm using a javascript SOAP client I've found here [guru4.net]. This client asks for the WSDL first, and does so by appending ?wsdl to the URL of the SOAP service.
So my simple SOAP service:
#!/usr/bin/perl use warnings; use strict; use lib '/home/hue/lang/perl/modules'; ## where Temperatures.pm lives use SOAP::Transport::HTTP; SOAP::Transport::HTTP::CGI->dispatch_to ('Temperatures')->handle;
Became:
#!/usr/bin/perl use warnings; use strict; use lib '/home/hue/lang/perl/modules'; use SOAP::Transport::HTTP; use CGI; my $q = CGI->new; my @keywords = $q->keywords; if (grep 'wsdl', @keywords) { print $q->header ('text/xml'); open my $fd, '<', 'temp.wsdl' or die "open: $!"; print while <$fd>; close $fd; exit; } SOAP::Transport::HTTP::CGI->dispatch_to ('Temperatures')->handle;
This code has a problem: CGI->new eats the input to the script and chokes on it. I remedied it by doing my $q = CGI->new ('') but this prevents me from accesing $q->keywords. So I had to resort to $ENV{'QUERY_STRING'}. The final code reads:
#!/usr/bin/perl use warnings; use strict; use lib '/home/hue/lang/perl/modules'; use SOAP::Transport::HTTP; use CGI; my $q = CGI->new (''); ## create empty query if ('wsdl' eq $ENV{'QUERY_STRING'}) { ## test for 'eq' is enough in t +his simple case print $q->header ('text/xml'); open my $fd, '<', 'temp.wsdl' or die "open: $!"; print while <$fd>; close $fd; exit; } SOAP::Transport::HTTP::CGI->dispatch_to ('Temperatures')->handle;
I realize that right now, CGI.pm is only used to send the proper header to the client. I think this is a good thing and see no point in removing CGI.pm from the equation, since probably Apache will have to load it for other scripts anyway. This runs under mod_perl, by the way.
Is this an acceptable way of doing it? Or is there a "better"TM method?
--
David Serrano
In reply to SOAP server must offer WSDL document too by Hue-Bond
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |