Developing Web Services Using JAX-WS : Web Services Annotations « Web Services SOA « Java Tutorial






import javax.jws.WebService;
import javax.jws.WebMethod;

@WebService(
    name="Calculator",
    serviceName="CalculatorService",
    targetNamespace="http://yourserver.com/sample"
)
public class Calculator {
        public Calculator() {}
        
        @WebMethod(operationName="add", action="urn:Add")
        public int add(int i, int j) {
            int k = i +j ;
            System.out.println(i + "+" + j +" = " + k);
            return k;
        }
}


import javax.xml.ws.WebServiceRef;

public class JAXWSClient {

  public static void main(String[] args) throws Exception {
    @WebServiceRef(wsdlLocation = "http://localhost:8080/jaxws-webservice/CalculatorService?WSDL")
    static CalculatorService service;

    Calculator port = service.getCalculatorPort();
    int ret = port.add(1, 10);
    System.out.println(ret);
  }
}








26.3.Web Services Annotations
26.3.1.The WebService annotation type elements
26.3.2.The WebMethod annotation type elements
26.3.3.The WebParam annotation type elements
26.3.4.The WebResult annotation type elements
26.3.5.Annotations Found in the javax.xml.bind.annotation Package
26.3.6.Create a simple Web Service
26.3.7.Developing Web Services Using JAX-WS