WSDL Tutorials - Herong's Tutorial Examples - v2.22, by Herong Yang
Creating Service Client with WSDL 1.1 Document
This section provides a tutorial example on how to create a ServiceClient object with a given WSDL document, a service name and a port name defined in the WSDL document.
Before looking at other Axis2 class, let's take a closer look at how to create a service client object from an existing WSDL document using this constructor method:
org.apache.axis2.client.ServiceClient client = new ServiceClient(null, wsdlURL, serviceQName, portName) // "null" indicates a default ConfigurationContext object to be used // "wsdlURL" specifies a WSDL document using a new URL(wsdlUrlString) // "serviceQName" specifies a service within the WSDL document // using a new QName(tns,serviceName) // "tns" specifies the target namespace of the Web service // "portName" specifies a port within the service using the port name
Now let's write a test program, Axis2ServiceClientHello.java, to create a service client with my hello WSDL document, which is located at https://www.herongyang.com/Service/Hello_WSDL_11_SOAP.wsdl.
/* Axis2ServiceClientHello.java * Copyright (c) 2009 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.context.ConfigurationContext; class Axis2ServiceClientHello { public static void main(String[] args) { PrintStream out = System.out; // Setting initial values ConfigurationContext config = null; String server = "https://www.herongyang.com/Service/"; String wsdl = server+"Hello_WSDL_11_SOAP.wsdl"; String tns = "https://www.herongyang.com/Service/"; String serviceName = "helloService"; String portName = "helloPort"; try { // Creating a dynamic service client with a given WSDL ServiceClient client = new ServiceClient( config, new URL(wsdl), new QName(tns, serviceName), portName); // Printing ServiceClient object information out.println(); out.println("ServiceClient object information:"); out.println(" client: "+client); out.println(" client.getAxisConfiguration(): " +client.getAxisConfiguration()); out.println(" client.getAxisService(): " +client.getAxisService()); out.println(" client.getOptions(): " +client.getOptions()); out.println(" client.getServiceContext(): " +client.getServiceContext()); out.println(" client.getTargetEPR(): " +client.getTargetEPR()); } catch (Exception e) { e.printStackTrace(); } } }
I can compile this program with the "-Djava.ext.dirs=\local\axis2\lib\" option with JDK 1.8 or earlier versions, so it will automatically all JAR files in that directory in the class path.
But with JDK 9 or higher, I got this error:
herong> javac -Djava.ext.dirs=\local\axis2\lib\ \ Axis2ServiceClientHello.java javac: option -extdirs not allowed with target 1.10
One workaround is the use "-cp .;\local\axis2\lib\*" option:
herong> javac -cp .;\local\axis2\lib\* Axis2ServiceClientHello.java herong> java -cp .;\local\axis2\lib\* Axis2ServiceClientHello log4j:WARN No appenders could be found for logger ... log4j:WARN Please initialize the log4j system properly. WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.apache.ws.commons.schema.utils.DOMUtil (file:/C:/local/axis2/lib/xmlschema-core-2.2.1.jar) to method com.sun.org.apache.xerces.internal.dom .CoreDocumentImpl.getXmlEncoding() WARNING: Please consider reporting this to the maintainers of org.apache.ws.commons.schema.utils.DOMUtil WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release ServiceClient object information: client: org.apache.axis2.client.ServiceClient@1 client.getAxisConfiguration(): org.apache.axis2.engine.AxisConfiguration@4c51cf28 client.getAxisService(): helloService client.getOptions(): org.apache.axis2.client.Options@6995bf68 client.getServiceContext(): org.apache.axis2.context.ServiceContext@5143c662 client.getTargetEPR(): null
Notes on the test program code and output:
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
Using WSDL Document in Java Apache Axis2/Java for WSDL
Apache Woden for WSDL Documents in Java
SoapUI - Web Service Testing Tool
WSDL 1.1 Document Structure and Syntax
WSDL 1.1 Binding Extension for SOAP 1.1
SoapUI as WSDL 1.1 Testing Tool
WSDL 1.1 and SOAP 1.1 Examples - Document and RPC Styles
PHP SOAP Extension for WSDL 1.1
►Apache Axis2/Java for WSDL 1.1
►Creating Service Client with WSDL 1.1 Document
org.apache.axis2.client.Options - Operation Client Options
sendReceive() Method - Invoking a Named Operation
Turning Off the Chunked HTTP Flag
Axis2RegistrationClient.java - document/literal Style
org.apache.axis2.rpc.client.RPCServiceClient Class
Axis2GetExchangeRateClient.java - rpc/encoded Style
SocketRequestResponseServer.java - Socket Server Testing Program
Capturing the HTTP Request from an Axis2 Client Program
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