# Generating Client Code for Web Services

You can generate client code to use with web services.

## Generating Client Code From a WSDL File

Using OEPE, you can generate the client code for the following types of projects:

- Web service project

- Dynamic Web project

- EJB project

To generate the client code for your Web service:

1. Create new, or obtain an existing WSDL file for your target Web service project.

   For more information, see the following:

   - Creating a new WSDL File

   - Generating a Web Service from a Java Class for JAX-WS

2. Create another Web service project, which will be your client project.

3. Copy the WSDL file (from step 1) located in the WebContent folder of your target Web service into the WebContent folder of your client project (from step 2).

4. Generate the client code as follows:

   - In the Project Explorer, right-click your client project's WSDL file, and then select WebLogic Web Services > Generate Web Service Client from the drop-down menu. This will open the New Web Service Client dialog.

   - On the New Web Service Client dialog, specify the service name, the output location of the generated JAR file, as well as Ant script generation options, and then click Next.

   - On the next New Web Service Client > Customization Options screen, you may choose to specify additional options, and then click Finish.

Upon completion of the preceding procedure, Eclipse does the following:

- Creates the client JAR file in your client Web service project's `WebContent/WEB-INF` directory.

- Modifies properties of your target Web service project, as necessary (sets the project facet, classpath, and so on).

If you deploy and run both your target and client Web service projects, your generated client code will successfully call your target Web service.

Note: Nondeployment-based applications, such as Java applications, may require additional manual configuration.

You can reference the client from the target Web service using the template-based code snippets.

## Generating Client Code from a Java Class

You can generate client code from Java classes.

To generate client code from a Java class:

1. On the Web Service Proxy Client Generation page, populate the following fields:

   - Project: Choose the project that will contain the proxy class as well as the class you want to generate the client invocation code from.

   - Client Proxy Class: Browse the current project for an existing WebService client, or choose to create a new webservice client using a local or remote WSDL.

   - Invocation Class: Choose a class file that you want to generate the client invocation into, or browse for an existing class.

   - Invocation Method: Choose the corresponding method that will contain the client invocation. The resulting code block will be generated at the end of the method block. You can also browse for existing methods.

2. On the Selection WebLogic Web Service Policies page, select either No Policies, OWSM Web Service Policies, or WebLogic Service Policies.

   Note: The Description section provides information about the currently selected policy.

   Within the OWSM policy panel, you can choose compatible client policies based on a resolved WSDL location. The WSDL location is based on the client service selection specified in the previous page (Web Service Proxy Client Generation). If the WSDL is packaged with the service, OEPE evaluates the WSDL for policy declarations and a compatible client list is displayed. Otherwise, you are presented with the entire client store of policies.

   As you select available policies, they are validated against each other for compatibility. If incompatible policies are selected, a validation error is displayed. If you click on the error marker, text describing the validation error is displayed. You will be required to resolve the validation errors prior to selecting Finish.

## Alternative Ways to Generate the Client Code

There are alternative entry points to the client code generation wizard. Instead of right-clicking your client project's WSDL file, and then selecting WebLogic Web Services > Generate Web Service Client from the drop-down menu, you may choose to right-click the Project Explorer area, select New > Other > WebLogic Web Services > Web Service Client, and then click Next. This will open the ClientGen Wizard > WSDL File dialog.

Using this dialog, select the WSDL file from which you want to generate the Web service client indicating if this file is local or remote (in this case, enter a remote URL), and then proceed with your other settings.

## Deploying Java Web Service Applications to Oracle WebLogic Server

Typically, Eclipse builds your files automatically and you can deploy your application at any time. Note that in order to deploy, you must have a successful build completed.

You can start Oracle Weblogic Server in either development or production mode: in development mode, the server behaves in ways that make it easier to iteratively develop and test applications (for example, the server automatically deploys the current application in an exploded format and relaxes certain security restrictions on deployment); in production mode, WebLogic Web Service test client is not deployed. For more information, see Testing Web Services.

Application deployment consists of the following three steps:

1. Compilation of the Web service.

2. Publishing the files to the server.

3. Running the application.

Usually these steps are done seamlessly, by explosion of the WAR file.

When you deploy, all open projects associated with the server are deployed. To undeploy a project or prevent it from being deployed, remove it from the server. Alternatively, you can close projects by selecting Project > Close Projects from the menu. You can also specify working sets (see Eclipse help system in the Workbench User Guide) to control how many artifacts to build and deploy.

However, even though an entire application or group of projects was deployed, only the file or folder that you clicked on to trigger the deployment will display its results. When you deploy your Web service, the test client page for that Web service will run in a new tab in the editor area - you can use it to specify the parameters to an operation and make a request to that operation. The response from the operation is displayed in the same tab. If the page flow or Web service relies on other Web services to run correctly, it will still work because all components are deployed.

To deploy your Web service application, do one of:

- Right-click your project in the Project Explorer and select Run As > Run on Server from the drop-down menu to start the server in normal mode (if it has not been started). This will deploy the application to its associated server; if the project is not associated with a server, make a server selection using the displayed dialog, and then run the application.

- Right-click your project in the Project Explorer and select Debug As > Debug on Server from the drop-down menu to start the server in debug mode (if it is not already started), and run the application.

If you wish to simply publish your files to the server, you can use the Servers view by selecting Window > Show View > Servers from the main menu.

Note: This view also lets you undeploy applications from the server.

After you deploy your application, the Servers view is displayed automatically.