2-4 Getting Started With JAX-WS Web Services for Oracle WebLogic Server
To run the Web service, you need to create a client that invokes it. See Section 2.4,
Invoking a Web Service from a Java SE Application for an example of creating a Java
client application that invokes a Web service.
2.1.1 Sample HelloWorldImpl.java JWS File
package examples.webservices.hello_world; Import the WebService annotation
import javax.jws.WebService; WebServicename=HelloWorldPortType, serviceName=HelloWorldService
This JWS file forms the basis of simple Java-class implemented WebLogic Web Service with a single operation: sayHelloWorld
public class HelloWorldImpl { By default, all public methods are exposed as Web Services operation
public String sayHelloWorldString message { try {
System.out.printlnsayHelloWorld: + message; } catch Exception ex { ex.printStackTrace; }
return Here is the message: + message + ; }
}
2.1.2 Sample Ant Build File for HelloWorldImpl.java
The following build.xml file uses properties to simplify the file. project name=webservices-hello_world 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=helloWorldEar property name=example-output value=output
property name=ear-dir value={example-output}helloWorldEar 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
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=exampleswebserviceshello_worldHelloWorldImpl.java
Use Cases and Examples 2-5
type=JAXWS 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}HelloWorldImplHelloWorldService?WSDL
destDir={clientclass-dir} packageName=examples.webservices.hello_world.client
type=JAXWS javac
srcdir={clientclass-dir} destdir={clientclass-dir} includes=.java
javac srcdir=src destdir={clientclass-dir}
includes=exampleswebserviceshello_worldclient.java target
target name=run java classname=examples.webservices.hello_world.client.Main
fork=true failonerror=true classpath refid=client.class.path
arg line=http:{wls.hostname}:{wls.port}HelloWorldImplHelloWorldService
java target project
2.2 Creating a Web Service With User-Defined Data Types