Java Reference
In-Depth Information
Coding SOAP web services with WildFly
In the first deliverable, we will show how easily you can turn a plain Java class into a web
service. The newly created service will then be tested using a simple Eclipse-based testing
GUI. The second part of this section will draw your attention to how EJBs can be exposed
as web service endpoints by enhancing your ticket application with a web service.
Developing a POJO web service
We will start developing web services, using our project from
Chapter 4
,
Learning Context
and Dependency Injection
(
ticket-agency-cdi
) as a base. We will omit the current
JSF-based web layer for now. You can safely remove all of the JSF-related classes and con-
figurations. If you encounter any problems, remember that you'll find a fully working pro-
ject in the code examples, upon completion of this chapter.
Our first class will not be related to our ticket application, but it will just demonstrate how
to create a web service from a
POJO
class named
CalculatePowerWebService
. This
class has a method named
calculatePower
, which returns the power of an argument,
as shown in the following highlighted code:
package com.packtpub.wflydevelopment.chapter7.boundary;
public class CalculatePowerWebService {
public double
calculatePower
(double base, double
exponent) {
return Math.pow(base, exponent);
}
}
Now, we will turn this simple class into a web service by adding the mandatory
@We-
bService
annotation:
package com.packtpub.wflydevelopment.chapter7.webservice;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;