package factorial; import jakarta.jws.WebMethod; import jakarta.jws.WebParam; import jakarta.jws.WebService; @WebService(serviceName = "Faktorial") public class Faktorial { @WebMethod(operationName = "faktorial") public long faktorial(@WebParam(name = "n") int n) { long result = 1; while (n > 1) result *= n--; return result; } }
package faktapp; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Named; import jakarta.xml.ws.WebServiceRef; @Named @RequestScoped public class FaktBean { public FaktBean() { } int n; long result; public int getN() { return n; } public void setN(int newN) { n = newN; } public long getResult() { return result; } public void setResult(long newResult) { result = newResult; } @WebServiceRef(wsdlLocation = "http://localhost:8080/FaktorialService/Faktorial?wsdl") private Faktorial_Service faktorialService; public void compute() { Faktorial faktorial = faktorialService.getFaktorialPort(); result = faktorial.faktorial(n); } }
<?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html"> <h:head> <title>Faktorial Service Client App</title> </h:head> <h:body> Hello from Faktorial Service Client App <h:form> Enter N=<h:inputText value="#{faktBean.n}"/> <h:commandButton label="xx" value="N!" action="#{faktBean.compute()}"/> Result=<h:outputText value="#{faktBean.result}"/> </h:form> </h:body> </html>
package userobj; public class Two { private int a; private int b; public int getA() { return a; } public void setA(int newA) { a = newA; } public int getB() { return b; } public void setB(int newB) { b = newB; } }
package userobj; import jakarta.jws.WebMethod; import jakarta.jws.WebParam; import jakarta.jws.WebService; @WebService(serviceName = "UserObj") public class UserObj { @WebMethod(operationName = "sum") public int sum(@WebParam(name = "obj") Two obj) { return obj.getA() + obj.getB(); } }
@WebServiceRef(wsdlLocation = "http://localhost:8080/WSwithUserObj/UserObj?wsdl") private UserObj_Service uoService; public void compute() { UserObj uo = uoService.getUserObjPort(); Two t = new Two(); t.setA(a); t.setB(b); result = uo.sum(t); }