Group:

I've written a (very) simplistic SoapServer class for Unicon that
can be used to construct SOAP servers that serve RPCs.  For
example, here's a server built using this class (minus the actual
URLs used when testing it):
------------------------------------------------------------------
#
# Test of a soap connection.
#

import soap

procedure main()
    server := SoapServer(SERVER_URL_GOES_HERE)
    server.addService("hi",   hi)
    server.addService("bye", bye)
    server.addService("guy", guy)
    msg := server.handleRequest()
    write(msg)
    exit(0)
end

procedure hi(a[])       # result is a string
    s := ""
    every s ||:= !a
    return ("Hi "||s)
end

procedure bye(a[])      # result is a table
    s := table()
    s["a1"] := a[1]
    s["a2"] := a[2]
    s["a3"] := a[3]
    return s
end

procedure guy(a[])      # result is a list
    s := list()
    every put(s := [], !a)
    return s
end
----------------------------------------------------------------------

Given the following perl SOAP client:

----------------------------------------------------------------------
#!/usr/bin/perl -w

use SOAP::Lite
    on_fault => sub { my($soap,$res) = @_;
        die ref $res ? $res->faultstring : $soap->transport->status, "
dead\n";
        };

my $soap = SOAP::Lite
  -> uri(SERVER_URL_GOES_HERE)
  -> proxy(SERVER_PROXY_GOES_HERE);

eval {
    $result = $soap->hi(1,2,3)->result;
    print "result: ",$result,"\n";
    print "\n";

    $result = $soap->bye(1,2,3)->result;
    print "a1: ",$result->{'a1'},"\n";
    print "a2: ",$result->{'a2'},"\n";
    print "a3: ",$result->{'a3'},"\n";
    print "\n";

    $result = $soap->guy(1,2,3)->result;
    print "a2: ",$result->[2],"\n";
    print "a0: ",$result->[0],"\n";
    print "a1: ",$result->[1],"\n";
    print "\n";

    } or die;
-----------------------------------------------------------------------

The output from this client, connecting to the above server, is:

-----------------------------------------------------------------------
result: Hi 123

a1: 1
a2: 2
a3: 3

a2: 3
a0: 1
a1: 2
-----------------------------------------------------------------------

The SoapServer class is sufficient for my immediate needs and I don't
have time to flesh it out to a 'production class' class, but if anyone
would like to see it [*and* improve it!] I'll be happy to pass it on.
The code depends upon having both Robert Parlett's class library and
a Unicon code library I've got.  Both (and the source for SoapServer)
can be reached through:

   http://tapestry.tuc.noao.edu/unicon

-- 
Steve Wampler <[EMAIL PROTECTED]>
National Solar Observatory


-------------------------------------------------------
This SF.net email is sponsored by: Scholarships for Techies!
Can't afford IT training? All 2003 ictp students receive scholarships.
Get hands-on training in Microsoft, Cisco, Sun, Linux/UNIX, and more.
www.ictp.com/training/sourceforge.asp
_______________________________________________
Unicon-group mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to