New GWT RemoteServices can be
created using the GWT RemoteServices wizard. The wizard can be
selected from the drop down wizard menu or from the
Eclipse New wizard.
To use the wizard, select the client package to contain the RemoteService. Then enter the service name and hit the Finish button.
GWT nature and builder automatically created during GWT Project creation.
Adding a method to the remote service interface class will automatically add the appropriate method to the matching *Async and *Impl classes.
Renaming or moving a remote service class renames the *Async and *Impl classes and servlet entry in the in module XML file.
The following is a simple example of RPC communication using Remote Services.
Person is the simple domain class used in the example. Note that it must be marked as serializable via the IsSerializable interface.
PersonsService is a RemoteService interface that defines a single method, getPersons(), that returns a list of Person objects from the server based on filter pattern that is passed in.
PersonsServiceAsync is an auto-generated class that facilitates communication with the server.
PersonsServiceImpl is the server side class that implements the actual logic of returning the list of customers based on the passed in pattern
SimpleRPC is the GWT GUI class that implements the user interface. The user can enter a filter and click the Show Persons button to retrieve a list of Person objects from the server.
Remote Services are runtime-only components and care must be taken when trying to use them at design time in a Composite class. GWT.create(MyService.class) needs to create an instance of the class that should invoke the RemoteService implementation on the application server. During design time the application server isn't running so this doesn't work. That means that code like the following will fail, if you try to use the custom Composite within another window at design time:
At design time, you will see an exception like the following:
The fix is to wrapper the RemoteService instantiation reference in an isDesignTime() check like this:
Make sure to also implement the isDesignTime() method exactly as shown. Return false for GWT 2.2 or earlier or Beans.isDesignTime() for GWT 2.4 and above. At design time, GWT Designer will then replace the "return false;" with "return true;" during class loading (it will compile normally and be ignored at runtime).