How Do I: Use the Java Proxy for a Web Service?

Using the Java proxy for a web service requires different steps depending on whether you use it from within WebLogic Server (as in a JSP or servlet) or from outside WebLogic Server (as in a standalone Java application).

Note:You can also call a web service from a page flow via a Web Service control. This approach is simpler than using the proxy.

Note: You should not use a Web Service control to invoke a web service that resides in the same application. Invoking a web service via a Web Service control means marshalling the method parameters into a SOAP message on the calling end and unmarshalling the SOAP message on the receiving end, then again for the method return value. This is very inefficient when the invocation is local. You would usually be tempted to invoke a local web service if the called web service includes business logic you want to access.

In general, you should place business logic in custom Java controls instead of in web services. This allows you to access the business logic from various contexts in the application (web services, other controls, page flows) without incurring the cost of data marshalling and unmarshalling. Web Service controls should only be used to invoke web services that are truly external to your application.

To Use the Java Proxy from a JSP

  1. Open your web service in WebLogic Workshop, then click the Start button to run the service. The Workshop Test (Test View) browser appears.
  2. Click the Overview tab.
  3. Under the Web Service Clients header click Java Proxy.
  4. When prompted, save the file to disk. Save the file to the WEB-INF/lib directory of the web application from which you wish to use the proxy. The default name of the file is <web service name>.jar; accept the default name unless it conflicts with an existing JAR file in WEB-INF/lib.

    If you want to use the web service proxy JAR from more than one project in your application, you can add it to the Libraries folder at the root of your application. Saving the JAR directly to the APP-INF/lib directory at the root of your application will automatically add the JAR file to the Libraries folder.

  5. In your JSP file, add an import of the web service proxy package as shown here:

    <%@ page import="weblogic.jws.proxies.*" %>

  6. Create an instance of the proxy class as shown below. The generic proxy class is the name of the web service with "_Impl" appended to the end:

    <% HelloWorld_Impl proxy = new HelloWorld_Impl(); %>

  7. The generic proxy returns protocol-specific proxies that in turn contain the actual interface of the web service. The following example assumes you wish to communicate with the web service using SOAP. Use other getHelloWorldXXX methods to get proxies for other protocols:

    <% HelloWorldSoap soapProxy = proxy.getHelloWorldSoap(); %>

  8. Call the appropriate methods on the protocol-specific proxy, as in the following example:

    <%= soapProxy.Hello() %>

Note that you will need to download a new copy of the proxy if you change any of the signatures of the web service methods or callbacks.

For an example that demonstrates use of a web service Java proxy from a JSP page, see Java Client Samples.

To Use the Java Proxy from a Java Project in WebLogic Workshop

  1. Follow steps 1 through 3 of the previous procedure to obtain the Java proxy JAR file.
  2. Save the JAR file to the APP-INF/lib directory for your application.

To Use the Java Proxy in a Separate Java Application

  1. Follow steps 1 through 3 of the first procedure to obtain the Java proxy JAR file.
  2. Save the JAR file to a location that is convenient for your Java application.
  3. From the Overview tab of Test View, click Proxy Support Jar and save the webserviceclient.jar file to the same location as the proxy JAR file.
  4. Use the proxy classes as described in the procedure for JSPs above. The following is an example of a Java client using the HelloWorld sample JWS:
    import weblogic.jws.proxies.*;
    public class Main
        public static void main(String[] args)
                HelloWorld_Impl proxy = new HelloWorld_Impl();
                HelloWorldSoap soapProxy = proxy.getHelloWorldSoap();
            catch (Exception e)
  5. Compile your source, including the JAR files saved in steps 2 and 3 on your class path.
  6. Run your Java application, including the two JAR files on your class path.

For examples that demonstrates use of a web service Java proxy from Java clients, see Java Client Samples.

Generating a Customized Java Proxy

WebLogic Workshop uses WebLogic Server's clientgen tool to generate the Java proxy for a web service, based on the web service's WSDL file. You may use the clientgen tool directly if you wish to customize the generated Java proxy. To learn more about clientgen, see the documentation for clientgen on

The clientgen tool accepts several command line parameters. The only parameter set by WebLogic Workshop when generating a Java proxy from Test View is the packageName parameter, which is always set to weblogic.jws.proxies.

Related Topics