You can invoke the remote services of any installed Liferay application the same way you invoke your local services. Doing so could be described as “invoking remote services locally.” One reason to invoke a remote service instead of the corresponding local service is to take advantage of the remote service’s permission checks. Consider the following common scenario:
- Both a local service implementation and a remote service implementation have been created for a particular service.
- The remote service performs a permission check and then invokes the corresponding local service.
In the above scenario, it’s a best practice to invoke the remote service instead
of the local service. Doing so ensures that you don’t need to duplicate
permission checking code. This is the practice followed by the services in
Liferay’s Web Content app.
Notice that the
addArticle methods invoke
journalArticleLocalService.addArticle after a permission check.
Of course, the main reason for creating remote services is to invoke them
remotely. Service Builder can expose your project’s remote web services both via
a JSON API and via SOAP. By default, running Service Builder with
remote-service set to
true for your entities generates a JSON web services
API for your project. You can access your project’s JSON-based RESTful services
through a convenient web interface.
Many default Liferay services are available as web services. Liferay exposes its web services via SOAP and JSON web services. If you’re running Liferay locally on port 8080, visit the following URL to browse Liferay’s default SOAP web services:
To browse Liferay’s default JSON web services, visit this URL:
By default, the context path is set to
/ which means that core Liferay
services are listed. By default, the http://localhost:8080/api/jsonws/ page
shows the JSON web services in the
portal context. You can select a different
context in the Context Name selector menu. For example, selecting
Context Name shows you the JSON web services in Liferay’s Web Content app
(this app’s entities all begin with
Journal*). You can also access a context’s
JSON web services via a direct URL. For example, the URL for the Web Content
app’s JSON web services is
Each entity’s available service methods appear in the left column of the
JSON web services page. To view details about a service method, click it. The
full package path to the service’s
*Impl class appears along with the
method’s parameters, return type, and possible exceptions. You can also invoke
the service from this page. For example, in the
portal context click the
get-entry method. This brings up that service
method’s details page, where you can also invoke the service.
The only parameter required to invoke the
get-entry method is an
invoke this web service, you could enter an announcement entry’s ID in the
entryId field and then click Invoke. Liferay returns feedback from each
invocation that indicates, for example, whether the service invocation succeeded
or failed. Invoking remote services in this manner is a great way to test your
app’s remote services.
Service Builder can also make your project’s web services available via SOAP
using Apache Axis. After you’ve built your
*-service project’s WSDD (web
service deployment descriptor) and deployed your project’s modules, its services
are available on your Liferay server. You can use your browser to view the SOAP
services of Liferay and Liferay apps as described in the tutorial
Creating Remote Services.
When viewing your SOAP services in a browser, Liferay lists the services available for all your entities and provides links to their WSDL documents. For example, clicking on the WSDL link for the User service takes you to the following URL:
This WSDL document lists the entity’s SOAP web services. Once the web service’s WSDL is available, any SOAP web service client can access it. To see examples of SOAP web service client implementations, see the tutorial SOAP Web Services.
Liferay web services are designed to be invoked by client applications. Liferay’s web services APIs can be accessed by many different kinds of clients, including non-portlet and even non-Java clients. For information on how to develop client applications that can access Liferay’s JSON web services, please see the Invoking JSON Web Services tutorial. For information on how to develop client applications that access Liferay’s SOAP web services, please see the SOAP Web Services tutorial. To learn how to create remote web services for your own application, please refer to the Creating Remote Services tutorial.
For more information on Liferay services, see the Liferay Portal CE Javadocs at https://docs.liferay.com/dxp/portal/7.0-latest/javadocs/.