Use Cases and Examples 2-3
See the outputhelloWorldEar directory to view the files and artifacts generated by the jwsc Ant task.
9.
Start the WebLogic Server instance to which the Web service will be deployed.
10.
Deploy the Web service, packaged in an enterprise application, to WebLogic Server, using either the Administration Console or the wldeploy Ant task. In
either case, you deploy the helloWorldEar Enterprise application, located in the output
directory. To use the wldeploy Ant task, add the following target to the build.xml file:
taskdef name=wldeploy classname=weblogic.ant.taskdefs.management.WLDeploy
target name=deploy wldeploy action=deploy
name=helloWorldEar source=outputhelloWorldEar user={wls.username} password={wls.password}
verbose=true adminurl=t3:{wls.hostname}:{wls.port}
targets={wls.server.name} target
Substitute the values for wls.username, wls.password, wls.hostname, wls.port
, and wls.server.name that correspond to your WebLogic Server instance.
Deploy the WAR file by executing the deploy target: prompt ant deploy
11.
Test that the Web service is deployed correctly by invoking its WSDL in your browser:
http:host:portHelloWorldImplHelloWorldImpl?WSDL You construct the URL using the values of the contextPath and serviceUri
attributes of the WLHttpTransport JWS annotation; however, because the JWS file in this use case does not include the WLHttpTransport annotation, use the
default values for the contextPath and serviceUri attributes: the name of the Java class in the JWS file. These attributes will be set explicitly in the next example,
Section 2.2, Creating a Web Service With User-Defined Data Types. Use the
hostname and port relevant to your WebLogic Server instance. You can use the clean, build-service, undeploy, and deploy targets in the
build.xml file to iteratively update, rebuild, undeploy, and redeploy the Web
service as part of your development process. 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 Client
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
2-4 Getting Started With JAX-RPC Web Services for Oracle WebLogic Server
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 type=JAXRPC
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
Use Cases and Examples 2-5
adminurl=t3:{wls.hostname}:{wls.port} targets={wls.server.name}
target target name=client
clientgen wsdl=http:{wls.hostname}:{wls.port}HelloWorldImplHelloWorldImpl?WSDL
destDir={clientclass-dir} packageName=examples.webservices.hello_world.client
type=JAXRPC 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}HelloWorldImplHelloWorldImpl
java target project
2.2 Creating a Web Service With User-Defined Data Types