Click here to Skip to main content
15,893,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
java code;
Java
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
    }
}

this is html and java script code but i cant able to run
XML
<!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);
}

kindly any one help me how to call webservice using java script
Posted
Updated 19-Apr-13 2:59am
v3
Comments
Prasad Khandekar 19-Apr-13 9:03am    
What errors are you getting? Have you tried using http://www.guru4.net/articoli/javascript-soap-client/en/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900