The JAX-RPC package aims to simplify the task of calling a remote Web Service. The API enables:
Stub generation
Both the service interface and the stub are generated from the WSDL description file using an appropriate tool. The service interface contains the signature of the remote methods and each of them is marked so that they can throw a RemoteException. The stub implements the service interface and javax.xml.rpc.Stub. In the example the service interface is called CapitalPortType and the stub CapitalBinding_Stub
Stub instantiation
The stub created in the previous step is instantiated and used either as the stub itself or via the service interface:
CapitalBinding_Stub stub = new CapitalBinding_Stub(); CapitalPortType capitals = (CapitalPortType)stub;
Stub operations
Once instantiated, the stub is used to set properties such as the endpoint address.
stub.setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, "http://194.137.80.38/CapitalService/Capitals");
The table below lists the properties supported by the stub.
Property |
Description |
---|---|
Stub.ENDPOINT_ADDRESS_PROPERTY |
Target service endpoint address |
Stub.PASSWORD_PROPERTY |
Password for authentication |
Stub.USERNAME_PROPERTY |
User name for authentication |
Stub.SESSION_MAINTAIN_PROPERTY |
Indicate whether or not a client wants to participate in a session with a service endpoint |
Finally, the Remote Procedure Call can be done calling some of the methods in the stub
String capitalName = capitals.getCapital("Australia");
It should also be considered that whenever a remote operation is called on the service interface, it will require a connection to the network, and following the recommendations for MIDP programming, this operation should be executed in a separate thread.
Packaging
The stub and service interface should be packaged in the MIDlet's JAR file.