Using the JAX-RPC package

The JAX-RPC package aims to simplify the task of calling a remote Web Service. The API enables:

  1. 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

  2. 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;
  3. 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.

    Table 10: Supported stub properties

    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.

  4. Packaging

    The stub and service interface should be packaged in the MIDlet's JAR file.