Skip navigation.
Downloads | Product Documentation | Support

Programming Web Services for WebLogic Server

# Common Web Services Use Cases and Examples

The following sections describe the most common Web Service use cases:

- Creating a Simple HelloWorld Web Service
- Creating a Web Service With User-Defined Data Types
- Creating a Web Service from a WSDL File
- Invoking a Web Service from a Stand-alone JAX-RPC Java Client
- Invoking a Web Service from a WebLogic Web Service

These use cases provide step-by-step procedures for creating simple WebLogic Web Services and invoking an operation from a deployed Web Service. Each use case includes basic Java code and Ant `build.xml` files that you can use either in your own development environment to recreate the example, or by following the instructions to create and run the example outside of an already setup development environment.

The use cases do not go into detail about the tools and technologies used in the examples. For detailed information about specific features, see the relevant topics in this guide, in particular:

- Iterative Development of WebLogic Web Services
- Programming the JWS File
- Advanced JWS Programming: Implementing Asynchronous Features
- Invoking Web Services
- Ant Task Reference

# Creating a Simple HelloWorld Web Service

This section describes how to create a very simple Web Service that contains a single operation. The JWS file that implements the Web Service uses just the one required JWS annotation: `@WebService`. A JWS file is a standard Java file that uses JWS metadata annotations to specify the shape of the Web Service. Metadata annotations are a new JDK 5.0 feature, and the set of annotations used to annotate Web Service files are called JWS annotations. WebLogic Web Services use standard JWS annotations, as defined by JSR-181, as well as WebLogic-specific ones for added value.

The following example shows how to create a Web Service called `HelloWorldService` that includes a single operation, `sayHelloWorld`. For simplicity, the operation does nothing other than return the inputted String value.

1. Open a command window and set your WebLogic Server environment by executing the `setDomainEnv.cmd` (Windows) or `setDomainEnv.sh` (UNIX) script, located in the `bin` subdirectory of your domain directory. The default location of WebLogic Server domains is `BEA_HOME``/user_projects/domains/``domainName`, where `BEA_HOME` is the top-level installation directory of the BEA products and `domainName` is the name of your domain.
2. Create a project directory:

>        prompt> mkdir /myExamples/hello_world

3. Create a `src` directory under the project directory, as well as sub-directories that correspond to the package name of the JWS file (shown later in this procedure):

>        prompt> cd /myExamples/hello_world
>        prompt> mkdir src/examples/webservices/hello_world

4. Create the JWS file that implements the Web Service by opening your favorite Java IDE or text editor and creating a Java file called `HelloWorldImpl.java` using the Java code specified in Sample HelloWorldImpl.java JWS File.

The sample JWS file shows a Java class called `HelloWorldImpl` that contains a single public method, `sayHelloWorld(String)`. The`@WebService` annotation specifies that the Java class implements a Web Service called `HelloWorldService`. By default, all public methods are exposed as operations.

5. Save the `HelloWorldImpl.java` file in the `src/examples/webservices/hello_world` directory.
6. Create a standard Ant `build.xml` file in the project directory and add a `taskdef` Ant task to specify the fully Java classname of the `jwsc` task:

>     <project name="webservices-hello_world" default="all">

>       <taskdef name="jwsc"
>                classname="weblogic.wsee.tools.anttasks.JwscTask" />

>     </project>

See Sample Ant Build File for HelloWorldImpl.java for a full sample `build.xml` file that contains additional targets from those described in this procedure, such as `clean`, `undeploy`, `client`, and `run`. The full `build.xml` file also uses properties, such as `${ear-dir}`, rather than always using the hard-coded name for the EAR directory.

7. Add the following call to the `jwsc` Ant task to the `build.xml` file, wrapped inside of the `build-service` target:

>       <target name="build-service">

>         <jwsc
>           srcdir="src"
>           destdir="output/helloWorldEar">

>           <jws file="examples/webservices/hello_world/HelloWorldImpl.java" />

>         </jwsc>

>       </target>

The `jwsc` WebLogic Web Service Ant task generates the supporting artifacts (such as the deployment descriptors, serialization classes for any user-defined data types, the WSDL file, and so on) , compiles the user-created and generated Java code, and archives all the artifacts into an Enterprise Application EAR file that you later deploy to WebLogic Server.

8. Execute the `jwsc` Ant task by specifying the `build-service` target at the command line:

>     prompt> ant build-service

See the `output/helloWorldEar` 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="output/helloWorldEar"
>                   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:port/HelloWorldImpl/HelloWorldImpl?WSDL

You construct this URL by specifying 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, specify the default values for the two attributes: the name of the Java class in the JWS file. Use the hostname and port relevant to your WebLogic Server instance.

See Invoking a Web Service from a Stand-alone JAX-RPC Java Client for an example of creating a JAX-RPC Java client application that invokes a Web Service.

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.

## Sample HelloWorldImpl.java JWS File

>     package examples.webservices.hello_world;

>     // Import the @WebService annotation

>     import javax.jws.WebService;

>     @WebService(name="HelloWorldPortType", serviceName="HelloWorldService")

>     /**
>      * This JWS file forms the basis of simple Java-class implemented WebLogic
>      * Web Service with a single operation: sayHelloWorld
>      *
>      * @author Copyright (c) 2005 by BEA Systems.  All rights reserved.
>      */

>     public class HelloWorldImpl {

>       // By default, all public methods are exposed as Web Services operation

>       public String sayHelloWorld(String message) {
>         System.out.println("sayHelloWorld:" + message);
>         return "Here is the message: '" + message + "'";
>       }
>     }

## 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="examples/webservices/hello_world/HelloWorldImpl.java" />

>         </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}/HelloWorldImpl/HelloWorldImpl?WSDL"
>           destDir="${clientclass-dir}"
>           packageName="examples.webservices.hello_world.client"/>

>         <javac
>           srcdir="${clientclass-dir}" destdir="${clientclass-dir}"
>           includes="**/*.java"/>

>         <javac
>           srcdir="src" destdir="${clientclass-dir}"
>           includes="examples/webservices/hello_world/client/**/*.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}/HelloWorldImpl/HelloWorldImpl"  />
>         </java> </target>

>     </project>

# Creating a Web Service With User-Defined Data Types

The preceding use case uses only a simple data type, `String`, as the parameter and return value of the Web Service operation. This next example shows how to create a Web Service that uses a user-defined data type, in particular a JavaBean called `BasicStruct`, as both a parameter and a return value of its operation.

There is actually very little a programmer has to do to use a user-defined data type in a Web Service, other than to create the Java source of the data type and use it correctly in the JWS file. The `jwsc` Ant task, when it encounters a user-defined data type in the JWS file, automatically generates all the data binding artifacts needed to convert data between its XML representation (used in the SOAP messages) and its Java representation (used in WebLogic Server.) The data binding artifacts include the XML Schema equivalent of the Java user-defined type, the JAX-RPC type mapping file, and so on.

The following procedure is very similar to the procedure in Creating a Simple HelloWorld Web Service. For this reason, although the procedure does show all the needed steps, it provides details only for those steps that differ from the simple HelloWorld example.

1. Open a command window and set your WebLogic Server environment.
2. Create a project directory:

>        prompt> mkdir /myExamples/complex

3. Create a `src` directory under the project directory, as well as sub-directories that correspond to the package name of the JWS file (shown later in this procedure):

>        prompt> cd /myExamples/complex

>        prompt> mkdir src/examples/webservices/complex

4. Create the source for the `BasicStruct` JavaBean by opening your favorite Java IDE or text editor and creating a Java file called `BasicStruct.java`, in the project directory, using the Java code specified in Sample BasicStruct JavaBean.
5. Save the `BasicStruct.java` file in the `src/examples/webservices/complex` sub-directory of the project directory.
6. Create the JWS file that implements the Web Service using the Java code specified in Sample ComplexImpl.java JWS File.

The sample JWS file uses more JWS annotations than in the preceding example: `@WebMethod` to specify explicitly that a method should be exposed as a Web Service operation and to change its operation name from the default method name `echoStruct` to `echoComplexType`; `@WebParam` and `@WebResult` to configure the parameters and return values; `@SOAPBinding` to specify the type of Web Service; and `@WLHttpTransport` to specify the URI used to invoke the Web Service. The `ComplexImpl.java` JWS file also imports the `examples.webservice.complex.BasicStruct` class and then uses the `BasicStruct` user-defined data type as both a parameter and return value of the `echoStruct()` method.

For more in-depth information about creating a JWS file, see Programming the JWS File.

7. Save the `ComplexImpl.java` file in the `src/examples/webservices/complex` sub-directory of the project directory.
8. Create a standard Ant `build.xml` file in the project directory and add a `taskdef` Ant task to specify the fully Java classname of the `jwsc` task:

>     <project name="webservices-complex" default="all">

>       <taskdef name="jwsc"
>                classname="weblogic.wsee.tools.anttasks.JwscTask" />

>     </project>

See Sample Ant Build File for ComplexImpl.java JWS File for a full sample `build.xml` file.

9. Add the following call to the `jwsc` Ant task to the `build.xml` file, wrapped inside of the `build-service` target:

>       <target name="build-service">

>         <jwsc
>           srcdir="src"
>           destdir="output/ComplexServiceEar" >
>           <jws file="examples/webservices/complex/ComplexImpl.java" />
>         </jwsc>

>       </target>

1. Execute the `jwsc` Ant task:

>     prompt> ant build-service

See the `output/ComplexServiceEar` directory to view the files and artifacts generated by the `jwsc` Ant task.

2. Start the WebLogic Server instance to which the Web Service will be deployed.
3. Deploy the Web Service, packaged in the `ComplexServiceEar` Enterprise Application, to WebLogic Server, using either the Administration Console or the `wldeploy` Ant task.
4. Test that the Web Service is deployed correctly by invoking its WSDL in your browser:

>     http://host:port/complex/ComplexService?WSDL

See Invoking a Web Service from a Stand-alone JAX-RPC Java Client for an example of creating a JAX-RPC Java client application that invokes a Web Service.

## Sample BasicStruct JavaBean

>     package examples.webservices.complex;

>     /**
>      * Defines a simple JavaBean called BasicStruct that has integer, String,
>      * and String[] properties
>      */

>     public class BasicStruct {

>       // Properties

>       private int intValue;
>       private String stringValue;
>       private String[] stringArray;

>       // Getter and setter methods

>       public int getIntValue() {
>         return intValue;
>       }

>       public void setIntValue(int intValue) {
>         this.intValue = intValue;
>       }

>       public String getStringValue() {
>         return stringValue;
>       }

>       public void setStringValue(String stringValue) {
>         this.stringValue = stringValue;
>       }

>       public String[] getStringArray() {
>         return stringArray;
>       }

>       public void setStringArray(String[] stringArray) {
>         this.stringArray = stringArray;
>       }

>       public String toString() {
>         return "IntValue="+intValue+", StringValue="+stringValue;
>       }
>     }

## Sample ComplexImpl.java JWS File

>     package examples.webservices.complex;

>     // Import the standard JWS annotation interfaces

>     import javax.jws.WebMethod;
>     import javax.jws.WebParam;
>     import javax.jws.WebResult;
>     import javax.jws.WebService;
>     import javax.jws.soap.SOAPBinding;

>     // Import the WebLogic-specific JWS annotation interface

>     import weblogic.jws.WLHttpTransport;

>     // Import the BasicStruct JavaBean

>     import examples.webservices.complex.BasicStruct;

>     // Standard JWS annotation that specifies that the portType name of the Web
>     // Service is "ComplexPortType", its public service name is "ComplexService",
>     // and the targetNamespace used in the generated WSDL is "http://example.org"

>     @WebService(serviceName="ComplexService", name="ComplexPortType",
>                 targetNamespace="http://example.org")

>     // Standard JWS annotation that specifies this is a document-literal-wrapped
>     // Web Service

>     @SOAPBinding(style=SOAPBinding.Style.DOCUMENT,
>                  use=SOAPBinding.Use.LITERAL,
>                  parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)

>     // WebLogic-specific JWS annotation that specifies the context path and service
>     // URI used to build the URI of the Web Service is "complex/ComplexService"

>     @WLHttpTransport(contextPath="complex", serviceUri="ComplexService",
>                      portName="ComplexServicePort")

>     /**
>      * This JWS file forms the basis of a WebLogic Web Service.  The Web Services
>      * has two public operations:
>      *
>      *  - echoInt(int)
>      *  - echoComplexType(BasicStruct)
>      *
>      * The Web Service is defined as a "document-literal" service, which means
>      * that the SOAP messages have a single part referencing an XML Schema element
>      * that defines the entire body.
>      *
>      * @author Copyright (c) 2005 by BEA Systems. All Rights Reserved.
>      */

>     public class ComplexImpl {

>       // Standard JWS annotation that specifies that the method should be exposed
>       // as a public operation.  Because the annotation does not include the
>       // member-value "operationName", the public name of the operation is the
>       // same as the method name: echoInt.
>       //
>       // The WebResult annotation specifies that the name of the result of the
>       // operation in the generated WSDL is "IntegerOutput", rather than the
>       // default name "return".   The WebParam annotation specifies that the input
>       // parameter name in the WSDL file is "IntegerInput" rather than the Java
>       // name of the parameter, "input".

>       @WebMethod()
>       @WebResult(name="IntegerOutput",
>                  targetNamespace="http://example.org/complex")
>       public int echoInt(
>           @WebParam(name="IntegerInput",
>                     targetNamespace="http://example.org/complex")
>           int input)

>       {
>         System.out.println("echoInt '" + input + "' to you too!");
>         return input;
>       }

>       // Standard JWS annotation to expose method "echoStruct" as a public operation
>       // called "echoComplexType"
>       // The WebResult annotation specifies that the name of the result of the
>       // operation in the generated WSDL is "EchoStructReturnMessage",
>       // rather than the default name "return".

>       @WebMethod(operationName="echoComplexType")
>       @WebResult(name="EchoStructReturnMessage",
>                  targetNamespace="http://example.org/complex")
>       public BasicStruct echoStruct(BasicStruct struct)

>       {
>         System.out.println("echoComplexType called");
>         return struct;
>       }
>     }

## Sample Ant Build File for ComplexImpl.java JWS File

The following `build.xml` file uses properties to simplify the file.

>     <project name="webservices-complex" 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="complexServiceEAR" />
>       <property name="example-output" value="output" />
>       <property name="ear-dir" value="${example-output}/complexServiceEar" />
>       <property name="clientclass-dir" value="${example-output}/clientclass" />

>       <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}"
>           keepGenerated="true"
>           >
>           <jws file="examples/webservices/complex/ComplexImpl.java" />
>         </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" failonerror="false"
>           name="${ear.deployed.name}"
>           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}/complex/ComplexService?WSDL"
>           destDir="${clientclass-dir}"
>           packageName="examples.webservices.complex.client"/>

>         <javac
>           srcdir="${clientclass-dir}" destdir="${clientclass-dir}"
>           includes="**/*.java"/>

>         <javac
>           srcdir="src" destdir="${clientclass-dir}"
>           includes="examples/webservices/complex/client/**/*.java"/>
>       </target>

>       <target name="run" >
>         <java fork="true"
>               classname="examples.webservices.complex.client.Main"
>               failonerror="true" >
>           <classpath refid="client.class.path"/>
>           <arg line="http://${wls.hostname}:${wls.port}/complex/ComplexService"
>      />
>         </java>
>       </target>

>     </project>

# Creating a Web Service from a WSDL File

Another typical use case of creating a Web Service is to start from an existing WSDL file, often referred to as the golden WSDL. A WSDL file is a public contract that specifies what the Web Service looks like, such as the list of supported operations, the signature and shape of each operation, the protocols and transports that can be used when invoking the operations, and the XML Schema data types that are used when transporting the data over the wire. Based on this WSDL file, you generate the artifacts that implement the Web Service so that it can be deployed to WebLogic Server. These artifacts include:

- The JWS interface file that represents the Java implementation of your Web Service.
- Data binding artifacts used by WebLogic Server to convert between the XML and Java representations of the Web Service parameters and return values.
- A JWS file that contains a partial implementation of the generated JWS interface.
- Optional Javadocs for the generated JWS interface.

You use the `wsdlc` Ant task to generate these artifacts. Typically you run this Ant task one time to generate a JAR file that contains the generated JWS interface file and data binding artifacts, then code the generated JWS file that implements the interface, adding the business logic of your Web Service. In particular, you add Java code to the methods that implement the Web Service operations so that the operations behave as needed and add additional JWS annotations.

Warning: The only file generated by the `wsdlc` Ant task that you update is the JWS implementation file; you never need to update the JAR file that contains the JWS interface and data binding artifacts.

After you have coded the JWS implementation file, you run the `jwsc` Ant task to generate the deployable Web Service, using the same steps as described in the preceding sections. The only difference is that you use the `compiledWsdl` attribute to specify the JAR file (containing the JWS interface file and data binding artifacts) generated by the `wsdlc` Ant task.

The following simple example shows how to create a Web Service from the WSDL file shown in Sample WSDL File. The Web Service has one operation, `getTemp`, that returns a temperature when passed a zip code.

1. Open a command window and set your WebLogic Server environment by executing the `setDomainEnv.cmd` (Windows) or `setDomainEnv.sh` (UNIX) script, located in the `bin` subdirectory of your domain directory. The default location of WebLogic Server domains is `BEA_HOME``/user_projects/domains/``domainName`, where `BEA_HOME` is the top-level installation directory of the BEA products and `domainName` is the name of your domain.
2. Create a working directory:

>       prompt> mkdir /myExamples/wsdlc

3. Put your WSDL file into an accessible directory on your computer. For the purposes of this example, it is assumed that your WSDL file is called `TemperatureService.wsdl` and is located in the `/myExamples/wsdlc/wsdl_files` directory. See Sample WSDL File for a full listing of the file.
4. Create a standard Ant `build.xml` file in the project directory and add a `taskdef` Ant task to specify the fully Java classname of the `wsdlc` task:

>     <project name="webservices-wsdlc" default="all">

>       <taskdef name="wsdlc"
>                classname="weblogic.wsee.tools.anttasks.WsdlcTask"/>

>     </project>

See Sample Ant Build File for TemperatureService for a full sample `build.xml` file that contains additional targets from those described in this procedure, such as `clean`, `undeploy`, `client`, and `run`. The full `build.xml` file also uses properties, such as `${ear-dir}`, rather than always using the hard-coded name for the EAR directory.

5. Add the following call to the `wsdlc` Ant task to the `build.xml` file, wrapped inside of the `generate-from-wsdl` target:

>       <target name="generate-from-wsdl">

>         <wsdlc
>             srcWsdl="wsdl_files/TemperatureService.wsdl"
>             destJwsDir="output/compiledWsdl"
>             destImplDir="output/impl"
>             packageName="examples.webservices.wsdlc" />

>       </target>

The `wsdlc` task in the examples generates the JAR file that contains the JWS interface and data binding artifacts into the `output/compiledWsdl` directory under the current directory. It also generates a partial implementation file (`TemperaturePortTypeImpl.java`) of the JWS interface into the `output/impl/examples/webservices/wsdlc` directory (which is a combination of the output directory specified by `destImplDir` and the directory hierarchy specified by the package name). All generated JWS files will be packaged in the `examples.webservices.wsdlc` package.

6. Execute the `wsdlc` Ant task by specifying the `generate-from-wsdl` target at the command line:

>     prompt> ant generate-from-wsdl

See the `output` directory if you want to examine the artifacts and files generated by the `wsdlc` Ant task.

7. Update the generated `output/impl/examples/webservices/wsdlc/TemperaturePortTypeImpl.java` JWS implementation file using your favorite Java IDE or text editor to add Java code to the methods so that they behave as you want. See Sample TemperaturePortType Java Implementation File for an example; the added Java code is in bold. The generated JWS implementation file automatically includes values for the `@WebService` and `@WLHttpTransport` JWS annotations that correspond to the values in the original WSDL file.

Warning: There are restrictions on the JWS annotations that you can add to the JWS implementation file in the "starting from WSDL" use case. See wsdlc for details.

For simplicity, the sample `getTemp()` method in `TemperaturePortTypeImpl.java` returns a hard-coded number. In real life, the implementation of this method would actually look up the current temperature at the given zip code.

8. Copy the updated `TemperaturePortTypeImpl.java` file into a permanent directory, such as a `src` directory under the project directory; remember to create child directories that correspond to the package name:

>     prompt> cd /examples/wsdlc
>     prompt> mkdir src/examples/webservices/wsdlc
>     prompt> cp output/impl/examples/webservices/wsdlc/TemperaturePortTypeImpl.java \
>                src/examples/webservices/wsdlc/TemperaturePortTypeImpl.java

1. Add a `build-service` target to the `build.xml` file that executes the `jwsc` Ant task against the updated JWS implementation class. Use the `compiledWsdl` attribute of `jwsc` to specify the name of the JAR file generated by the `wsdlc` Ant task:

>       <taskdef name="jwsc"
>         classname="weblogic.wsee.tools.anttasks.JwscTask" />

>       <target name="build-service">

>        <jwsc
>           srcdir="src"
>           destdir="${ear-dir}">
>           <jws
>               file="examples/webservices/wsdlc/TemperaturePortTypeImpl.java"
>                compiledWsdl="output/compiledWsdl/TemperatureService_wsdl.jar"
>           />
>        </jwsc>

>       </target>

1. Execute the `build-service` target to generate a deployable Web Service:

>     prompt> ant build-service

You can iteratively keep rerunning this target if you want to update the JWS file bit by bit.

2. Start the WebLogic Server instance to which the Web Service will be deployed.
3. 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 `wsdlcEar` 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="wsdlcEar"
>           source="output/wsdlcEar" 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

4. Test that the Web Service is deployed correctly by invoking its WSDL in your browser:

>     http://host:port/temp/TemperatureService?WSDL

The context path and service URI section of the preceding URL are specified by the original golden WSDL. Use the hostname and port relevant to your WebLogic Server instance. Note that the deployed and original WSDL files are the same, except for the host and port of the endpoint address.

See Invoking a Web Service from a Stand-alone JAX-RPC Java Client for an example of creating a JAX-RPC Java client application that invokes a Web Service.

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.

## Sample WSDL File

>     <?xml version="1.0"?>

>     <definitions
>        name="TemperatureService"
>        targetNamespace="http://www.bea.com/wls90"
>        xmlns:tns="http://www.bea.com/wls90"
>        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>        xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
>        xmlns="http://schemas.xmlsoap.org/wsdl/" >

>             <message name="getTempRequest">
>                     <part name="zip" type="xsd:string"/>
>             </message>

>             <message name="getTempResponse">
>                     <part name="return" type="xsd:float"/>
>             </message>

>             <portType name="TemperaturePortType">
>                     <operation name="getTemp">
>                             <input message="tns:getTempRequest"/>
>                             <output message="tns:getTempResponse"/>
>                     </operation>
>             </portType>

>             <binding name="TemperatureBinding" type="tns:TemperaturePortType">
>                     <soap:binding style="rpc"
>                                  transport="http://schemas.xmlsoap.org/soap/http"/>
>                     <operation name="getTemp">
>                             <soap:operation soapAction=""/>
>                             <input>
>                                     <soap:body use="literal"
>                                      namespace="http://www.bea.com/wls90" />
>                             </input>
>                             <output>
>                                     <soap:body use="literal"
>                                      namespace="http://www.bea.com/wls90" />
>                             </output>
>                     </operation>
>             </binding>

>             <service name="TemperatureService">
>                 <documentation>
>                     Returns current temperature in a given U.S. zipcode
>                 </documentation>
>                 <port name="TemperaturePort" binding="tns:TemperatureBinding">
>                    <soap:address
>                               location="http://localhost:7001/temp/TemperatureService"/>
>                 </port>
>             </service>

>     </definitions>

## Sample TemperaturePortType Java Implementation File

>     package examples.webservices.wsdlc;

>     import javax.jws.WebService;
>     import weblogic.jws.*;

>     /**
>      * TemperaturePortTypeImpl class implements web service endpoint interface TemperaturePortType */

>     @WebService(
>       serviceName="TemperatureService",
>       endpointInterface="examples.webservices.wsdlc.TemperaturePortType")

>     @WLHttpTransport(
>       contextPath="temp",
>       serviceUri="TemperatureService",
>       portName="TemperaturePort")
>     public class TemperaturePortTypeImpl implements TemperaturePortType {

>       public TemperaturePortTypeImpl() {

>       }

>       public float getTemp(java.lang.String zip)

>       {
>          return 1.234f;
>       }
>     }

## Sample Ant Build File for TemperatureService

The following `build.xml` file uses properties to simplify the file.

>     <project 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="wsdlcEar" />
>       <property name="example-output" value="output" />
>       <property name="compiledWsdl-dir" value="${example-output}/compiledWsdl" />
>       <property name="impl-dir" value="${example-output}/impl" />
>       <property name="ear-dir" value="${example-output}/wsdlcEar" />
>       <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="wsdlc"
>                classname="weblogic.wsee.tools.anttasks.WsdlcTask"/>

>       <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,generate-from-wsdl,build-service,deploy,client" />

>       <target name="clean" depends="undeploy">
>         <delete dir="${example-output}"/>
>       </target>

>       <target name="generate-from-wsdl">

>         <wsdlc
>             srcWsdl="wsdl_files/TemperatureService.wsdl"
>             destJwsDir="${compiledWsdl-dir}"
>             destImplDir="${impl-dir}"
>             packageName="examples.webservices.wsdlc" />

>       </target>

>       <target name="build-service">

>         <jwsc
>           srcdir="src"
>           destdir="${ear-dir}">

>           <jws file="examples/webservices/wsdlc/TemperaturePortTypeImpl.java"
>                compiledWsdl="${compiledWsdl-dir}/TemperatureService_wsdl.jar" />

>         </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}/temp/TemperatureService?WSDL"
>           destDir="${clientclass-dir}"
>           packageName="examples.webservices.wsdlc.client"/>

>         <javac
>           srcdir="${clientclass-dir}" destdir="${clientclass-dir}"
>           includes="**/*.java"/>

>         <javac
>           srcdir="src" destdir="${clientclass-dir}"
>           includes="examples/webservices/wsdlc/client/**/*.java"/>

>       </target>

>       <target name="run">
>         <java classname="examples.webservices.wsdlc.client.TemperatureClient"
>              fork="true" failonerror="true" >
>           <classpath refid="client.class.path"/>
>           <arg
>               line="http://${wls.hostname}:${wls.port}/temp/TemperatureService" />
>         </java>

>       </target>

>     </project>

# Invoking a Web Service from a Stand-alone JAX-RPC Java Client

When you invoke an operation of a deployed Web Service from a client application, the Web Service could be deployed to WebLogic Server or to any other application server, such as .NET. All you need to know is the URL to its public contract file, or WSDL.

In addition to writing the Java client application, you must also run the `clientgen` WebLogic Web Service Ant task to generate the artifacts that your client application needs to invoke the Web Service operation. These artifacts include:

- Java source code for the JAX-RPC `Stub` and `Service` interface implementations for the particular Web Service you want to invoke.
- Java classes for any user-defined XML Schema data types included in the WSDL file.
- JAX-RPC mapping deployment descriptor file which contains information about the mapping between the Java data types and their corresponding XML Schema types in the WSDL file.
- Client-side copy of the WSDL file.

The following example shows how to create a Java client application that invokes the `echoComplexType` operation of the `ComplexService` WebLogic Web Service described in Creating a Web Service With User-Defined Data Types. The `echoComplexType` operation takes as both a parameter and return type the `BasicStruct` user-defined data type. It is assumed in this procedure that you have already created and deployed the `ComplexService` Web Service.

1. Open a command window and set your WebLogic Server environment by executing the `setDomainEnv.cmd` (Windows) or `setDomainEnv.sh` (UNIX) script, located in the `bin` subdirectory of your domain directory. The default location of WebLogic Server domains is `BEA_HOME``/user_projects/domains/``domainName`, where `BEA_HOME` is the top-level installation directory of the BEA products and `domainName` is the name of your domain.
2. Create a project directory:

>        prompt> mkdir /myExamples/simple_client

3. Create a `src` directory under the project directory, as well as sub-directories that correspond to the package name of the Java client application (shown later on in this procedure):

>        prompt> cd /myExamples/simple_client
>        prompt> mkdir src/examples/webservices/simple_client

4. Create a standard Ant `build.xml` file in the project directory and add a `taskdef` Ant task to specify the fully Java classname of the `clientgen` task:

>     <project name="webservices-simple_client" default="all">

>       <taskdef name="clientgen"
>         classname="weblogic.wsee.tools.anttasks.ClientGenTask" />

>     </project>

See Sample Ant Build File For Building Stand-alone Client Application for a full sample `build.xml` file The full `build.xml` file uses properties, such as `${clientclass-dir}`, rather than always using the hard-coded name output directory for client classes.

5. Add the following calls to the `clientgen` and `javac` Ant tasks to the `build.xml` file, wrapped inside of the `build-client` target:

>       <target name="build-client">

>         <clientgen
>           wsdl="http://${wls.hostname}:${wls.port}/complex/ComplexService?WSDL"
>           destDir="output/clientclass"
>           packageName="examples.webservices.simple_client"/>

>         <javac
>           srcdir="output/clientclass" destdir="output/clientclass"
>           includes="**/*.java"/>

>      <javac
>         srcdir="src" destdir="output/clientclass"
>         includes="examples/webservices/simple_client/*.java"/>

>     </target>

The `clientgen` Ant task uses the WSDL of the deployed `ComplexService` Web Service to generate the needed artifacts and puts them into the `output/clientclass` directory, using the specified package name. Replace the variables with the actual hostname and port of your WebLogic Server instance that is hosting the Web Service.

The `clientgen` Ant task also automatically generates the `examples.webservices.complex.BasicStruct` JavaBean class, which is the Java representation of the user-defined data type specified in the WSDL.

The `build-client` target also specifies the standard `javac` Ant task, in addition to `clientgen`, to compile all the Java code, including the stand-alone Java program described in the next step, into class files.

1. Create the Java client application file that invokes the `echoComplexType` operation by opening your favorite Java IDE or text editor, creating a Java file called `Main.java` using the code specified in Sample Java Client Application.

The `Main` client application takes a single argument: the WSDL URL of the Web Service. The application then follows standard JAX-RPC guidelines to invoke an operation of the Web Service using the Web Service-specific implementation of the `Service` interface generated by `clientgen`. The application also imports and uses the `BasicStruct` user-defined type, generated by the `clientgen` Ant task, that is used as a parameter and return value for the `echoStruct` operation. For details, see Invoking Web Services.

2. Save the `Main.java` file in the `src/examples/webservices/simple_client` sub-directory of the main project directory.
3. Execute the `clientgen` and `javac` Ant tasks by specifying the `build-client` target at the command line:

>     prompt> ant build-client

See the `output/clientclass` directory to view the files and artifacts generated by the `clientgen` Ant task.

4. Add the following targets to the `build.xml` file, used to execute the `Main` application:

>       <path id="client.class.path">
>         <pathelement path="output/clientclass"/>
>         <pathelement path="${java.class.path}"/>
>       </path>

>       <target name="run" >

>         <java fork="true"
>               classname="examples.webservices.simple_client.Main"
>               failonerror="true" >
>           <classpath refid="client.class.path"/>
>           <arg
>      line="http://${wls.hostname}:${wls.port}/complex/ComplexService"
>           />
>         </java>

>       </target>

The `run` target invokes the `Main` application, passing it the WSDL URL of the deployed Web Service as its single argument. The `classpath` element adds the `clientclass` directory to the CLASSPATH, using the reference created with the `<path>` task.

5. Execute the `run` target to invoke the `echoComplexType` operation:

>         prompt> ant run

If the invoke was successful, you should see the following final output:

>     run:
>          [java] echoComplexType called. Result: 999, Hello Struct

You can use the `build-client` and `run` targets in the `build.xml` file to iteratively update, rebuild, and run the Java client application as part of your development process.

## Sample Java Client Application

>     package examples.webservices.simple_client;

>     import java.rmi.RemoteException;

>     import javax.xml.rpc.ServiceException;

>     // import the BasicStruct class, used as a param and return value of the
>     // echoComplexType operation.  The class is generated automatically by
>     // the clientgen Ant task.

>     import examples.webservices.complex.BasicStruct;

>     /**
>      * This is a simple stand-alone client application that invokes the
>      * the echoComplexType operation of the ComplexService Web service.
>      *
>      * @author Copyright (c) 2005 by BEA Systems. All Rights Reserved.
>      */

>     public class Main {

>       public static void main(String[] args)
>           throws ServiceException, RemoteException{

>         ComplexService service = new ComplexService_Impl (args[0] + "?WSDL" );
>         ComplexPortType port = service.getComplexServicePort();

>         BasicStruct in = new BasicStruct();

>         in.setIntValue(999);
>         in.setStringValue("Hello Struct");

>         BasicStruct result = port.echoComplexType(in);
>         System.out.println("echoComplexType called. Result: " + result.getIntValue() + ", " + result.getStringValue());
>       }
>     }

## Sample Ant Build File For Building Stand-alone Client Application

The following `build.xml` file uses properties to simplify the file.

>     <project name="webservices-simple_client" default="all">

>       <!-- set global properties for this build -->

>       <property name="wls.hostname" value="localhost" />
>       <property name="wls.port" value="7001" />

>       <property name="example-output" value="output" />
>       <property name="clientclass-dir" value="${example-output}/clientclass" />

>       <path id="client.class.path">
>         <pathelement path="${clientclass-dir}"/>
>         <pathelement path="${java.class.path}"/>
>       </path>

>       <taskdef name="clientgen"
>         classname="weblogic.wsee.tools.anttasks.ClientGenTask" />

>       <target name="clean" >
>         <delete dir="${clientclass-dir}"/>
>       </target>

>       <target name="all" depends="clean,build-client,run" />

>       <target name="build-client">

>         <clientgen
>           wsdl="http://${wls.hostname}:${wls.port}/complex/ComplexService?WSDL"
>           destDir="${clientclass-dir}"
>           packageName="examples.webservices.simple_client"/>

>         <javac
>           srcdir="${clientclass-dir}" destdir="${clientclass-dir}"
>           includes="**/*.java"/>

>         <javac
>           srcdir="src" destdir="${clientclass-dir}"
>           includes="examples/webservices/simple_client/*.java"/>
>       </target>

>       <target name="run" >
>         <java fork="true"
>               classname="examples.webservices.simple_client.Main"
>               failonerror="true" >
>           <classpath refid="client.class.path"/>
>           <arg line="http://${wls.hostname}:${wls.port}/complex/ComplexService"
>      />
>         </java>
>       </target>

>     </project>

# Invoking a Web Service from a WebLogic Web Service

You can also invoke a Web Service (WebLogic, .NET, and so on) from within a deployed WebLogic Web Service, rather than from a stand-alone client. The procedure is similar to that described in Invoking a Web Service from a Stand-alone JAX-RPC Java Client. You run the `clientgen` Ant task to generate the client stubs and follow standard JAX-RPC guidelines in the client application; however, in this case, you use the JAX-RPC APIs in the JWS file that implements the Web Service that invokes the other Web Service rather than in the stand-alone Java client application.

The following example shows how to write a JWS file that invokes the `echoComplexType` operation of the `ComplexService` Web Service described in Creating a Web Service With User-Defined Data Types; it is assumed that you have successfully deployed the `ComplexService` Web Service.

1. Open a command window and set your WebLogic Server environment by executing the `setDomainEnv.cmd` (Windows) or `setDomainEnv.sh` (UNIX) script, located in the `bin` subdirectory of your domain directory. The default location of WebLogic Server domains is `BEA_HOME``/user_projects/domains/``domainName`, where `BEA_HOME` is the top-level installation directory of the BEA products and `domainName` is the name of your domain.
2. Create a project directory:

>        prompt> mkdir /myExamples/service_to_service

3. Create a `src` directory under the project directory, as well as sub-directories that correspond to the package name of the JWS and client application files (shown later on in this procedure):

>        prompt> cd /myExamples/service_to_service
>        prompt> mkdir src/examples/webservices/service_to_service

4. Create the JWS file that implements the Web Service that invokes the `ComplexService` Web Service. Open your favorite Java IDE or text editor and create a Java file called `ClientServiceImpl.java` using the Java code specified in Sample ClientServiceImpl.java JWS File.

The sample JWS file shows a Java class called `ClientServiceImpl` that contains a single public method, `callComplexService()`. The Java class imports the JAX-RPC stubs, generated later on by the `clientgen` Ant task, as well as the `BasicStruct` JavaBean (also generated by `clientgen`), which is data type of the parameter and return value of the `echoComplexType` operation of the `ComplexService` Web Service.

The `ClientServiceImpl` Java class defines one method, `callComplexService()`, which takes two parameters: a `BasicStruct` which is passed on to the `echoComplexType` operation of the `ComplexService` Web Service, and the URL of the `ComplexService` Web Service. The method then uses the standard JAX-RPC APIs to get the `Service` and `PortType` of the `ComplexService`, using the stubs generated by `clientgen`, and then invokes the `echoComplexType` operation.

5. Save the `ClientServiceImpl.java` file in the `src/examples/webservices/service_to_service` directory.
6. Create a standard Ant `build.xml` file in the project directory and add the following tasks:

>     <project name="webservices-service_to_service" default="all">

>       <path id="ws.clientService.class.path">
>         <pathelement path="output/tempjardir"/>
>         <pathelement path="${java.class.path}"/>
>       </path>

>       <taskdef name="jwsc"
>         classname="weblogic.wsee.tools.anttasks.JwscTask" />

>       <taskdef name="clientgen"
>         classname="weblogic.wsee.tools.anttasks.ClientGenTask" />

>     </project>

The `path` task sets up the `ws.clientService.class.path` variable which will later be used to add to the CLASSPATH. The `taskdef` tasks to define the full classname of the `jwsc` and `clientgen` Ant tasks.

See Sample Ant Build File For Building ClientService for a full sample `build.xml` file that contains additional targets from those described in this procedure, such as `clean`, `deploy`, `undeploy`, `client`, and `run`. The full `build.xml` file also uses properties, such as `${clientService-ear-dir}`, rather than always using the hard-coded name for the EAR directory.

7. Add the following calls to the `clientgen`., `jwsc`, `javac`, and `copy` Ant tasks to the `build.xml` file, wrapped inside of the `build-service` target:

>       <target name="build-service">

>         <clientgen
>           wsdl="http://${wls.hostname}:${wls.port}/complex/ComplexService?WSDL"
>           destDir="output/tempjardir"
>           packageName="examples.webservices.service_to_service"/>

>         <javac
>           source="1.5"
>           srcdir="output/tempjardir"
>           destdir="output/tempjardir"
>           includes="**/*.java"/>

>         <jwsc
>             srcdir="src"
>             destdir="output/ClientServiceEar"
>             classpathref="ws.clientService.class.path">

>             <jws
>              file="examples/webservices/service_to_service/ClientServiceImpl.java" />

>         </jwsc>

>         <copy todir="output/ClientServiceEar/APP-INF/classes">
>              <fileset dir="output/tempjardir" />
>         </copy>

>       </target>

In the preceding example, you first run use `clientgen` and `javac` to generate and compile the JAX-RPC stubs for the deployed `ComplexService` Web Service; this is because the `ClientServiceImpl` JWS file, which invokes `ComplexService`, imports these generated classes, and the `jwsc` task will fail if these classes do not already exist. When you execute the `jwsc` Ant task, use the `classpathref` attribute to add to the CLASSPATH the temporary directory into which `clientgen` generated its artifacts.

You then use the `copy` Ant task to copy the `clientgen`-generated artifacts into the `APP-INF/classes` directory of the EAR so that the `ClientService` Web Service can find them.

Note: The `APP-INF/classes` directory is a WebLogic-specific feature for sharing classes in an Enterprise application.

1. Execute the `clientgen`, `jwsc`, `javac`, and `copy` Ant tasks by specifying the `build-service` target at the command line:

>     prompt> ant build-service

See the `output/ClientServiceEar` directory and temporary `output/tempjardir` directory, to view the files and artifacts generated by the `jwsc` and `clientgen` Ant tasks.

2. Start the WebLogic Server instance to which you will deploy the Web Service.
3. 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 `ClientServiceEar` 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="ClientServiceEar"
>           source="ClientServiceEar" 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

4. Test that the Web Service is deployed correctly by invoking its WSDL in your browser:

>     http://host:port/ClientService/ClientService?WSDL

See Invoking a Web Service from a Stand-alone JAX-RPC Java Client for an example of creating a JAX-RPC Java client application that invokes a Web Service.

## Sample ClientServiceImpl.java JWS File

>     package examples.webservices.service_to_service;

>     import java.rmi.RemoteException;
>     import javax.xml.rpc.ServiceException;

>     import javax.jws.WebService;
>     import javax.jws.WebMethod;

>     import weblogic.jws.WLHttpTransport;

>     // Import the BasicStruct data type, generated by clientgen and used
>     // by the ComplexService Web Service

>     import examples.webservices.complex.BasicStruct;

>     // Import the JAX-RPC Stubs for invoking the ComplexService Web Service.
>     // Stubs generated by clientgen

>     import examples.webservices.service_to_service.ComplexPortType;
>     import examples.webservices.service_to_service.ComplexService_Impl;
>     import examples.webservices.service_to_service.ComplexService;

>     @WebService(name="ClientPortType", serviceName="ClientService",
>                 targetNamespace="http://examples.org")

>     @WLHttpTransport(contextPath="ClientService", serviceUri="ClientService",
>                      portName="ClientServicePort")

>     public class ClientServiceImpl {

>       @WebMethod()
>       public String callComplexService(BasicStruct input, String serviceUrl)
>           throws ServiceException, RemoteException
>       {

>         // Create service and port stubs to invoke ComplexService
>         ComplexService service = new ComplexService_Impl(serviceUrl + "?WSDL");
>         ComplexPortType port = service.getComplexServicePort();

>         // Invoke the echoComplexType operation of ComplexService
>         BasicStruct result = port.echoComplexType(input);
>         System.out.println("Invoked ComplexPortType.echoComplexType." );

>         return "Invoke went okay!  Here's the result: '" + result.getIntValue() + ",  " + result.getStringValue() + "'";

>       }
>     }

## Sample Ant Build File For Building ClientService

The following `build.xml` file uses properties to simplify the file.

>     <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="clientService.ear.deployed.name" value="ClientServiceEar" />
>       <property name="example-output" value="output" />
>       <property name="tempjar-dir" value="${example-output}/tempjardir" />
>       <property name="clientService-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>

>       <path id="ws.clientService.class.path">
>         <pathelement path="${tempjar-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">

>         <clientgen
>           wsdl="http://${wls.hostname}:${wls.port}/complex/ComplexService?WSDL"
>           destDir="${tempjar-dir}"
>           packageName="examples.webservices.service_to_service"/>

>         <javac
>           source="1.5"
>           srcdir="${tempjar-dir}"
>           destdir="${tempjar-dir}"
>           includes="**/*.java"/>

>         <jwsc
>             srcdir="src"
>             destdir="${clientService-ear-dir}"
>             classpathref="ws.clientService.class.path">

>             <jws
>              file="examples/webservices/service_to_service/ClientServiceImpl.java"
>            />

>         </jwsc>

>         <copy todir="${clientService-ear-dir}/APP-INF/classes">
>              <fileset dir="${tempjar-dir}" />
>         </copy>

>       </target>

>       <target name="deploy">
>         <wldeploy action="deploy" name="${clientService.ear.deployed.name}"
>           source="${clientService-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="${clientService.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}/ClientService/ClientService?WSDL"
>           destDir="${clientclass-dir}"
>           packageName="examples.webservices.service_to_service.client"/>

>         <javac
>           srcdir="${clientclass-dir}" destdir="${clientclass-dir}"
>           includes="**/*.java"/>

>         <javac
>           srcdir="src" destdir="${clientclass-dir}"
>           includes="examples/webservices/service_to_service/client/**/*.java"/>

>       </target>

>       <target name="run">
>         <java classname="examples.webservices.service_to_service.client.Main"
>               fork="true"
>               failonerror="true" >
>               <classpath refid="client.class.path"/>
>               <arg
>                   line="http://${wls.hostname}:${wls.port}/ClientService/ClientService"
>              />
>         </java>

>       </target>

>     </project>