6-12 Getting Started With JAX-RPC Web Services for Oracle WebLogic Server
6.3.2 Sample JWS File That Invokes a Web Service
The following sample JWS file, called ClientServiceImpl.java, implements a Web service called ClientService that has an operation that in turn invokes the
echoComplexType operation of a Web service called ComplexService. This
operation has a user-defined data type BasicStruct as both a parameter and a return value. The relevant code is shown in bold and described after the example.
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;
WebServicename=ClientPortType, serviceName=ClientService, targetNamespace=http:examples.org
WLHttpTransportcontextPath=ClientService, serviceUri=ClientService, portName=ClientServicePort
public class ClientServiceImpl { WebMethod
public String callComplexServiceBasicStruct input, String serviceUrl throws ServiceException, RemoteException
{ Create service and port stubs to invoke ComplexService
ComplexService service = new ComplexService_ImplserviceUrl + ?WSDL; ComplexPortType port = service.getComplexServicePort;
Create service and port stubs to invoke ComplexService
ComplexService service = new ComplexService_ImplserviceUrl + ?WSDL; ComplexPortType port = service.getComplexServicePortTypePort;
Invoke the echoComplexType operation of ComplexService BasicStruct result = port.echoComplexTypeinput;
System.out.printlnInvoked ComplexPortType.echoComplexType. ; return Invoke went okay Heres the result: + result.getIntValue + ,
+ result.getStringValue + ; }
}
Follow these guidelines when programming the JWS file that invokes another Web service; code snippets of the guidelines are shown in bold in the preceding example:
■
Import any user-defined data types that are used by the invoked Web service. In this example, the ComplexService uses the BasicStruct JavaBean:
import examples.webservices.complex.BasicStruct;
■
Import the JAX-RPC stubs of the ComplexService Web service; the stubs are generated by the cliengen child element of jws:
import examples.webservices.service_to_service.ComplexPortType; import examples.webservices.service_to_service.ComplexService_Impl;
import examples.webservices.service_to_service.ComplexService;
Invoking Web Services 6-13
■
Ensure that your client Web service throws or catches ServiceException and RemoteException
: throws ServiceException, RemoteException
■
Create the JAX-RPC Service and PortType instances for the ComplexService
: ComplexService service = new
ComplexService_ImplserviceUrl + ?WSDL; ComplexPortType port = service.getComplexServicePortTypePort;
■
Invoke the echoComplexType operation of ComplexService using the port you just instantiated:
BasicStruct result = port.echoComplexTypeinput;
6.4 Using a Stand-Alone Client JAR File When Invoking Web Services