WSDL Tutorials - Herong's Tutorial Examples - Version 2.03, by Dr. Herong Yang
Java Axis2 1.4.1 - RPC Method Based Web Services
This section provides a tutorial example on how to write a Java program to call an XML document based Web service with SOAP 1.2 binding using the RPCServiceClient class provided in Axis2 1.4.1.
The next test, of course, is the Registration XML document based Web service.
Here is the example Java program, Axis2RegistrationSoap12Client.java:
/** * Axis2RegistrationSoap12Client.java * Copyright (c) 2009 by Dr. Herong Yang, herongyang.com * All rights reserved */ import java.io.PrintStream; import java.net.URL; import javax.xml.namespace.QName; import org.apache.axis2.client.ServiceClient; import org.apache.axis2.client.Options; import org.apache.axis2.transport.http.HTTPConstants; import org.apache.axiom.om.OMAbstractFactory; import org.apache.axiom.om.OMElement; import org.apache.axiom.om.OMFactory; import org.apache.axiom.om.OMNamespace; class Axis2RegistrationSoap12Client { public static void main(String[] args) { PrintStream out = System.out; // Setting initial values String wsdl = "http://www.herongyang.com/Service/"; wsdl += "Registration_WSDL_11_SOAP_12_Document.wsdl"; String tns = "http://www.herongyang.com/Service/"; String serviceName = "registrationService"; String portName = "registrationPort"; try { ServiceClient client = new ServiceClient(null, new URL(wsdl), new QName(tns, serviceName), portName); Options option = client.getOptions(); option.setProperty(HTTPConstants.CHUNKED,false); // Building SOAP Body element for the request OMFactory factory = OMAbstractFactory.getOMFactory(); OMNamespace namespace = factory.createOMNamespace(tns, "hy"); OMElement request = factory.createOMElement( "RegistrationRequest", namespace); request.addAttribute("event", "OpenGame", namespace); request.addAttribute("date", "2008-08-08", namespace); OMElement guest1 = factory.createOMElement( "Guest", namespace); guest1.setText("Herong Yang"); request.addChild(guest1); OMElement guest2 = factory.createOMElement( "Guest", namespace); guest2.setText("Joe Smith"); request.addChild(guest2); // Printing the request as an XML string out.println(); out.println("Request XML message"); out.println(request); OMElement response = client.sendReceive( new QName(tns, "Registration"), request); // Printing the response as an XML string out.println(); out.println("Response XML message"); out.println(response); } catch (Exception e) { e.printStackTrace(); } } }
Here is the result of this tutorial program:
C:\herong>\local\jdk\bin\javac -Djava.ext.dirs=\local\axis2\lib\ Axis2RegistrationSoap12Client.java C:\herong>\local\jdk\bin\java -Djava.ext.dirs=\local\axis2\lib\ Axis2RegistrationSoap12Client log4j:WARN No appenders could be found for logger (org.apache.axis2.description. WSDL11ToAxisServiceBuilder). log4j:WARN Please initialize the log4j system properly. Request XML message <hy:RegistrationRequest xmlns:hy="http://www.herongyang.com/Service/" hy:event="OpenGame" hy:date="2008-08-08"> <hy:Guest>Herong Yang</hy:Guest> <hy:Guest>Joe Smith</hy:Guest> </hy:RegistrationRequest> Response XML message <hy:RegistrationResponse xmlns:hy="http://www.herongyang.com/Service/"> <hy:Confirmation guest="Herong Yang" event="OpenGame" /> <hy:Confirmation guest="Joe Smith" event="OpenGame" /> <hy:Confirmation guest="Bill Wang" event="OpenGame" /> </hy:RegistrationResponse>
Cool. This confirms that Axis2 1.4.1 does support XML document based Web services defined in WSDL 1.1 with SOAP 1.2 binding.
Last update: 2009.
Table of Contents
WSDL 2.0 Document Structure and Syntax
WSDL Version 2.0 Part 2: Adjuncts
WSDL 2.0 Document Examples with SOAP Binding
WSDL 20 Programming APIs and Testing Tools
WSDL 1.1 Document Structure and Syntax
WSDL 1.1 Binding Extension for SOAP 1.1
soapUI 3.0.1 - Web Service Testing Tool
WSDL 1.1 and SOAP 1.1 Examples - Document and RPC Styles
PHP SOAP Extension in PHP 5.3.1
Using WSDL in Perl with SOAP::Lite 0.710
Using WSDL Document in Java with Axis2 1.4.1
Using WSDL2Java to Generate Web Service Stub Classes
WSDL 1.1 Binding Extension for SOAP 1.2
WSDL 1.1 and SOAP 1.2 Examples - Document and RPC Styles
►SOAP 1.2 Binding - PHP, Java and Perl Clients
PHP SOAP Extension - RPC Method Based Web Services
PHP SOAP Extension - XML Document Based Web Services
Java Axis2 1.4.1 - XML Document Based Web Services
►Java Axis2 1.4.1 - RPC Method Based Web Services