...
As per JAX-RPC a Service Endpoint Interface must extend Remote. JAX-WS removes this condition and you can pretty much make a POJO class Web Service by just adding the @WebService
annotation at the top of the class.
Code Block |
---|
borderStyle | solid |
---|
title | JAX-RPC Converter SEI |
---|
borderStyle | solid |
---|
|
package org.apache.geronimo.samples.jaxrpc;
import java.math.BigDecimal;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Converter extends Remote {
public BigDecimal dollarToRupees(BigDecimal dollars) throws RemoteException;
public BigDecimal rupeesToEuro(BigDecimal rupees) throws RemoteException;
}
|
Code Block |
---|
borderStyle | solid |
---|
title | JAX-WS Converter SEI |
---|
borderStyle | solid |
---|
|
package org.apache.geronimo.samples.jaxrpc;
import java.math.BigDecimal;
import javax.jws.WebService
@WebService(name = "Converter", targetNamespace = "http://org.apache.geronimo.samples.jaxws")
public interface Converter {
public BigDecimal dollarToRupees(BigDecimal dollars);
public BigDecimal rupeesToEuro(BigDecimal rupees);
}
|
...
The following code samples demonstrate the difference between JAX-RPC and JAX-WS in client port lookup.
Code Block |
---|
borderStyle | solid |
---|
title | JAX-RPC Converter Client |
---|
borderStyle | solid |
---|
|
package org.apache.geronimo.samples.jaxrpc;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.ServiceException;
//a part of client
URL url = new URL("http://localhost:8080/jaxrpc-converter/converter?wsdl");
QName qname = new QName("http://org.apache.geronimo.samples.jaxrpc/","ConverterService");
ServiceFactory factory = ServiceFactory.newInstance();
Service service = factory.createService(url, qname);
Converter conv = (Converter) service.getPort(Converter.class);
|
Code Block |
---|
borderStyle | solid |
---|
title | JAX-WS Converter Client |
---|
borderStyle | solid |
---|
|
package org.apache.geronimo.samples.jaxrpc;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
//a part of client
URL url = new URL("http://localhost:8080/jaxrpc-converter/converter?wsdl");
QName qname = new QName("http://org.apache.geronimo.samples.jaxrpc/","ConverterService");
Service service = Service.create(url, qname);
Converter conv = (Converter) service.getPort(Converter.class);
|
...