Startseite bisherige Projekte Tools/Snippets Bücherempfehlungen Publikationen Impressum Datenschutzerklärung

Datenübertragung mit SOAPirgendwann 2008

Einige Beispiele zur Verwendung von SOAP.

Perl server

#!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";
}

sub echo {
    my ($text) = @_;
    return "you said:".$text."!";
}

Perl client

#!perl -w

use SOAP::Lite;

my $result = SOAP::Lite
->uri('http://www.soaplite.com/Demo')
->proxy('http://localhost/cgi-bin/server.pl')
->echo("Hallo Welt!");

unless ( $result->fault ) {
    print $result->result()."\n";
}
else {
    print join ', ', $result->faultcode, $result->faultstring;
}

Java client

import javax.xml.rpc.ParameterMode;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;


public class SoapTest {

    public static void main(String[] args) throws Exception{
                
        String endpoint = "http://localhost/cgi-bin/server.pl";
        String uri = "http://www.soaplite.com/Demo";

        String method = "echo";

        // Make the call
        String argument = "Guten Tag!!";

        Service  service = new Service();
        Call     call    = (Call) service.createCall();
        
        call.setTargetEndpointAddress(new java.net.URL(endpoint));
        call.setOperationName( method );
        call.addParameter("op1", XMLType.XSD_STRING, ParameterMode.IN);
        call.setReturnType(XMLType.XSD_STRING);

        String ret = (String) call.invoke(uri, method, new Object [] { argument });

        System.out.println("Got result : " + ret);
    }
    
}
Impressum - Datenschutzerklärung