A Web service is technology that enables public access to system functions as a service via a network. Web services are being acclaimed as a method that promotes efficient utilization of existing systems and reuse of software.
Use of SOAP, using HTTP for low-level protocol, for communications and use of WSDL to define the interfaces of published services have become the standards for implementing such Web services.
In addition, interoperability is an important aspect of Web services, and ambiguous constraints and Web service specifications (SOAP/WSDL/UDDI and so on) are clarified by being prescribed by WS-I Basic Profile.
In practice, Web service provision is implemented by providing a Service Endpoint, and the Service Endpoint Interface is determined on the basis of the following conventions:
SOAP
SOAP is a protocol for communication between objects via a network. Data structures that use XML for coding are prescribed, but the protocol used to send data is not prescribed and a variety of protocols, including HTTP and SMTP, can be used. However, in many cases, HTTP is generally used.
JAX-WS
JAX-WS is a successor of the JAX-RPC prescribed for implementing application remote invocation (Remote Procedure Call) using Java. To code the functions published as Web services using Java, create them within the range of this convention.
WSDL
WSDL is the coding method used to publish Web service specifications to users. Coding is in XML.
WS-I Basic Profile 1.1
In terms of interoperability improvements, the WS-I Basic Profile 1.1 conventions prescribe more detailed restrictions concerning the standard Web service specifications of SOAP/WSDL/UDDI and so on. Users generally do not need to be aware of the content of conventions during processes involved in creating a Web service application using the workbench. However, users do need to be aware of conventions when directly creating and publishing WSDL.
WS-I Attachments Profile 1.0
The WS-I Attachments Profile 1.0 conventions are based on SOAP Messages with Attachments, and clarify the SOAP and WSDL definition specifications and set limits to the usage range in order to improve the interoperability of Web services when file attachments are used. Web services that conform to WS-I Attachments Profile provide improved interoperability between systems when sending and receiving SOAP messages with attachments.
Point
The development method can be either top-down development, in which the Service Endpoint Interface is designed using WSDL, or bottom-up development, in which the Java class that will be the Service Endpoint is created and the Service Endpoint Interface is determined as a result of that.
The following specification differences exist between J2EE1.4 Web services and Java EE Web services:
JAX-RPC and JAX-WS
Under J2EE1.4, Web services conformed to JAX-RPC, but Web service development that conforms to JAX-WS is recommended under Java EE.
Files that configure a Web service
Under J2EE1.4, numerous files, such as an SEI (Service Endpoint Interface), implementation class, WSDL, mapping file, deployment descriptor, and so on, are required in order to create a Web service. However, under Java EE, a Web service can be created simply by declaring the @WebService annotation in the Java class.
Web service invocation method
Under Java EE, Dependency Injection can be used for Web services and also to easily code conventional lookup processing.
Simple examples of the main annotations used during Web service development are shown below while introducing Web services under Java EE.
javax.jws.WebService Annotation
This annotation defines a class as a Web service. The following properties can be specified.
Property Name | Explanation |
---|---|
endpointInterface | Define the Service Endpoint Interface if you do not want to make all the class methods public, and use this property to declare it. |
name | Name of the WSDL portType |
portName | Name of the WSDL port |
serviceName | Name of the WSDL service |
targetNamespace | WSDL namespace |
wsdlLocation | Use this property if a Web service is published based on an already defined WSDL. |
Example of using the WebService Annotation to create a Web Service
package sample; import javax.jws.WebService; @WebService(endpointInterface="sample.Calc") public class CalcImpl implements Calc { public int add(int param1,int param2) { return param1 + param2; } } |
javax.xml.ws.WebServiceRef Annotation
This annotation sets a Dependency Injection when invoking a Web service. The following properties can be specified.
Property Name | Explanation |
---|---|
mappedName | Mapped resource name |
name | JNDI name |
type | Java type of the resource |
value | Service class Normally, javax.xml.ws.Service is inherited. |
wsdlLocation | Specify the WSDL location. |
Example of using the WebServiceRef Annotation to create a Web Service Client
@WebServiceRef(name="service/Calc") private CalcService service; public int callCalc(int param1,int param2) { Calc port = service.getCalcPort(); return port.add(param1,param2); } |