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 JavaServer Page or servlet) or from outside WebLogic Server (as in a standalone Java 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.

2. In Test View, click the Overview tab.

3. Under Web Service Clients, 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.

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.

To Use the Java Proxy in a Separate Java Application

1. Follow steps 1 through 3 of the procedure above 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 using the HelloWorld sample JWS:

       		import weblogic.jws.proxies.*;
       		public class Main
       		{
       		    public static void main(String[] args)
       		    {
       		        try
       		        {
       		            HelloWorld_Impl proxy = new HelloWorld_Impl();
       		            HelloWorldSoap soapProxy = proxy.getHelloWorldSoap();
       		            System.out.println(soapProxy.Hello());
       		        }
       		        catch (Exception e)
       		        {
       		            e.printStackTrace();
       		        }
       		    }
       		}

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.

Related Topics

Test View