Invoking Web Services 6-9
The following list describes the changes you must make to the build.xml file that builds your client Web service, which will invoke another Web service. See
Section 6.3.1, Sample build.xml File for a Web Service Client for the full sample
build.xml file:
■
Add a clientgen child element to the jws element that specifies the JWS file that implements the Web service that invokes another Web service. Set the
required wsdl attribute to the WSDL of the Web service to be invoked. Set the required packageName attribute to the package into which you want the JAX-WS
client stubs to be generated.
The following list describes the changes you must make to the JWS file that implements the client Web service; see
Section 6.3.2, Sample JWS File That Invokes a Web Service
for the full JWS file example.
■
Import the files generated by the clientgen child element of the jwsc Ant task. These include the JAX-WS Service interface of the invoked Web service, as
well as the Java representation of any user-defined data types used as parameters or return values in the operations of the invoked Web service.
■
Get the Service and PortType interface implementation and invoke the operation on the port as usual; see
Section 6.2.3, Writing the Java Client Application Code to Invoke a Web Service
for details.
6.3.1 Sample build.xml File for a Web Service Client
The following sample build.xml file shows how to create a Web service that itself invokes another Web service; the relevant sections that differ from the build.xml for
building a simple Web service that does not invoke another Web service are shown in bold
. The build-service target in this case is very similar to a target that builds a simple
Web service; the only difference is that the jwsc Ant task that builds the invoking Web service also includes a clientgen child element of the jws element so that
jwsc also generates the required JAX-WS client stubs.
project name=webservices-service_to_service default=all -- set global properties for this build --
property name=wls.username value=weblogic property name=wls.password value=weblogic
property name=wls.hostname value=localhost property name=wls.port value=7001
property name=wls.server.name value=myserver property name=ear.deployed.name value=ClientServiceEar
property name=example-output value=output property name=ear-dir value={example-output}ClientServiceEar
property name=clientclass-dir value={example-output}clientclasses path id=client.class.path
pathelement path={clientclass-dir} pathelement path={java.class.path}
path taskdef name=jwsc
classname=weblogic.wsee.tools.anttasks.JwscTask
Note: If the package name set using the packageName attribute of
clientgen is set to the same package name as the client
application, then you are not required to import the clientgen
-generated files.
6-10 Getting Started With JAX-WS Web Services for Oracle WebLogic Server
taskdef name=clientgen classname=weblogic.wsee.tools.anttasks.ClientGenTask
taskdef name=wldeploy classname=weblogic.ant.taskdefs.management.WLDeploy
target name=all depends=clean,build-service,deploy,client target name=clean depends=undeploy
delete dir={example-output} target
target name=build-service jwsc
srcdir=src destdir={ear-dir}
jws file=exampleswebservicesservice_to_serviceClientServiceImpl.java
type=JAXWS clientgen
wsdl=http:{wls.hostname}:{wls.port}complexComplexService?WSDL packageName=examples.webservices.complex
jws jwsc
target target name=deploy
wldeploy action=deploy name={ear.deployed.name} source={ear-dir} user={wls.username}
password={wls.password} verbose=true adminurl=t3:{wls.hostname}:{wls.port}
targets={wls.server.name} target
target name=undeploy wldeploy action=undeploy name={ear.deployed.name}
failonerror=false user={wls.username}
password={wls.password} verbose=true adminurl=t3:{wls.hostname}:{wls.port}
targets={wls.server.name} target
target name=client clientgen
wsdl=http:{wls.hostname}:{wls.port}ClientServiceClientService?WSDL destDir={clientclass-dir}
packageName=examples.webservices.service_to_service.client type=JAXWS
javac srcdir={clientclass-dir} destdir={clientclass-dir}
includes=.java javac
srcdir=src destdir={clientclass-dir} includes=exampleswebservicesservice_to_serviceclient.java
target target name=run
java classname=examples.webservices.service_to_service.client.Main fork=true
failonerror=true classpath refid=client.class.path
java target
project
Invoking Web Services 6-11
6.3.2 Sample JWS File That Invokes a Web Service