28.3. Services development

28.3.1. Generate WSDL-files

This list should work as guide when creating new web service in BASE.

  1. Create a new class that extends AbstractRPCService

  2. Place the new service in same package as the abstract class, net.sf.basedb.ws.server

  3. Write the routines/methods the service should deploy.

    [Warning] Never return void from methods

    For server-side exceptions to be propagated to the client the web services method mustn't be declared as void. We suggest that in cases where there is no natural return value, the session ID is returned, for example:

    public String myMethod(String ID, ...more parameters...)
    {
      // ... your code here
      return ID;
    }
    
  4. Make the Ant build-file creates a WSDL-file when the services are compiled (see below). This step is not needed for BASE to work but may be appreciated by client application developers.

  5. Register the service in the <base-dir>/src/webservices/server/META-INF/services.xml file. This is an XML file listing all services and is needed for BASE (Axis) to pick up the new service and expose it to the outside world. Below is an example of hoe the Session service is registered.

    Example 28.1.  How to register a service in services.xml

    
    <service name="Session" scope="application">  
       <description>  
          This service handles BASE sessions (including login/logout)  
       </description>  
       <messageReceivers>  
          <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"   
             class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />  
          <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"   
             class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />  
       </messageReceivers>  
       <parameter name="ServiceClass" 
          locked="false">net.sf.basedb.ws.server.SessionService</parameter>  
    </service>  
    
    


28.3.1. Generate WSDL-files

When a new service is created it can be a good idea to also get a WSDL-file generated when the web services are compiled. The WSDL-file will be a help for those developers who intend to create client applications to the new service. It is a one-liner in the Ant build file to do this and not very complicated. To create a WSDL file for the new web service add a line like the one below to the webservices.wsdl target. Replace SessionService with the name of the new service class.

<webservices.wsdl serviceClassName="SessionService"/>