import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; import javax.xml.ws.Endpoint; @WebService public class Area { @WebMethod public double square(@WebParam(name="side") double side) { return side * side; } @WebMethod public double rectangle(@WebParam(name="length") double length,@WebParam(name="breadth") double breadth) { return length * breadth; } public static void main(String[] args) { Area area = new Area(); String url = "http://localhost:8080/area"; // end point of webservice. System.out.println(url+"?wsdl"); Endpoint.publish(url, area); // publishing the webservice } }
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script language="javascript"> function call() { var side = sideid.value; var req = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"http://ws.example.com/\"><soapenv:Body><web:square><side>" + side+ "</side></web:square></soapenv:Body></soapenv:Envelope>"; var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); var reqXML = xmlDoc.loadXML(req); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { var response = xmlhttp.responseXML; alert(response.selectSingleNode(".//return").text); } } var soapaction = "http://ws.example.com/square"; xmlhttp.open("POST","http://localhost:8080/area?wsdl",true); xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); xmlhttp.setRequestHeader("SOAPAction", soapaction); xmlhttp.send(req); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)