I am new to Java and trying to jump into WebServices. I found two examples somewhere and I am confused with the available options.
Firstly, javax.jws.WebService
with annotation seem to work fine, but there is loads of material on javax.xml.ws
. It seems javax.jws
is newer and there is not much material available about it.
What is the difference between these two approaches?
javax.jws. WebMethod. The @WebMethod annotation denotes a method that is a web service operation. Apply this annotation to methods on a client or server Service Endpoint Interface (SEI) or a server endpoint implementation class. Annotation target: Method.
Uses of Endpoint in javax.xml.wsCreates an endpoint with the specified binding type, implementor object, and web service features. Creates and publishes an endpoint for the specified implementor object at the given address. Creates and publishes an endpoint for the specified implementor object at the given address.
The annotation @WebService tells the server runtime environment to expose all public methods on that bean as a web service. You can control more levels of granularity by adding other annotations on individual methods or parameters. Using annotations makes it much easier to expose Java artifacts as web services.
JAX-WS RI 2.3. 1 is a Web Services framework that provides tools and infrastructure to develop Web Services solutions for the end users and middleware developers. With JAX-WS RI 2.3. 1, clients and web services have a big advantage: the platform independence of the Java programming language.
Using annotations from the JSR 181 specification (java.jws.xxx
), you can annotate a Web service implementation class or a Web service interface.
e.g. from Deploy JAX-WS Web Services On Tomcat
package com.mkyong.ws;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
//Service Endpoint Interface
@WebService
@SOAPBinding(style = Style.RPC)
public interface HelloWorld{
@WebMethod String getHelloWorldAsString();
}
The JSR 224 specification defines annotations for JAX-WS 2.0 (javax.xml.ws.xxx
).
e.g. from Using SOAP Faults and Exceptions in Java JAX-WS
@WebFault(name="CheckVerifyFault",
targetNamespace="http://www.example.com")
public class CheckVerifyFault extends Exception {
/**
* Java type that goes as soapenv:Fault detail element.
*/
private CheckFaultBean faultInfo;
public CheckVerifyFault(String message, CheckFaultBean faultInfo) {
super(message);
this.faultInfo = faultInfo;
}
public CheckVerifyFault(String message, CheckFaultBean faultInfo,
Throwable cause) {
super(message, cause);
this.faultInfo = faultInfo;
}
public CheckFaultBean getFaultInfo() {
return faultInfo;
}
}
Peer Reynders says:
My guess would be that BEA wanted something NOW to put into Weblogic to compete with the equivalent feature in .NET. (see, developing Web services in WebLogic is just "as easy"). Also the annotations specified in JAX-WS 2.0 (JSR-224)
seemto provide you with more control. However JSR-224 does explicitly support/include JSR-181 (JSR-224: 7.10 Annotations Defined by JSR-181).
For a more complete discussion about, see JSR 181: a Java Simplification Request
See also:
These two package namespaces do not define different approaches.
javax.xml.ws
and javax.jws
package namespaces. If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With