Perl Tutorial : Perl data types
Perl Tutorial : Perl Operators
Perl Tutorial : Perl loops
Perl Tutorial : Perl Conditionals
Perl Tutorial : Perl Subroutines
Perl Tutorial : Perl regex
Perl Tutorial : Perl Files
Perl Tutorial : Perl & Databases
Perl Tutorial : Perl OOPs
Perl Tutorial : Perl signals
Perl Tutorial : Perl threads
Perl Tutorial : Perl Debugging

Introcution to Perl CGI

Introduction to modperl
Home >> perlsoap >>

Writing a CGI-based Server

Here's a simple CGI-based SOAP server:

1.a. server (hibye.cgi)

#!perl -w
use SOAP::Transport::HTTP;
SOAP::Transport::HTTP::CGI   
    -> dispatch_to('Demo')     
    -> handle;
package Demo;
sub hi {                     
    return "hello, world";     
}
sub bye {                    
    return "goodbye, cruel world";
}

There are basically two parts to this: the first four lines set up a SOAP wrapper around a class. Everything from 'package Demo' onward is the class being wrapped.

In the previous version of the SOAP specification (1.0), SOAP over HTTP was supposed to use a new HTTP method, M-POST. In practice, there are many web servers that don't understand the M-POST method so this requirement was weakened and now it's common to try a normal POST first and then use M-POST if the server needs it. If you don't understand POST and M-POST, don't worry, you don't need to know all about it to use the module.

Writing a Client
This program prints the results of the hi() method call:
1.a. client (hibye.pl)

#!perl -w
use SOAP::Lite;
print SOAP::Lite
    -> uri('http://www.gnulamp.com/Demo')
    -> proxy('http://soap.gnulamp.com/hibye.cgi')
    -> hi()
    -> result;

The uri() identifies the class on the server, and the proxy() identifies the CGI script that provides access to the class. Since both look like URLs, I'll take a minute to explain the difference, as it's quite important. proxy()
proxy() is simply the address of the server to contact that provides the methods. You can use http:, mailto:, even ftp: URLs here.


Perl functions

scalars and strings

lc
ord

regex (regular expressions)

arrays

shift
split

More..

eval
Share |


Perl examples

  • How to use Data::Dumper?
  • How to parse config file?
  • Include external module in perl..
  • Download perl

    download stable version of perl
    Perl 5.10.1
    Perl interview Questions
    sed tutorial
    awk tutorial

    Join us on Google Groups

    Subscribe to perl
    Email:
    Visit this group
    Perl Jobs


    privacy | sitemap | disclaim | contact us
    © 2009 perlhome.com