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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.