-通过ajax调用webService--
1.肯定有服务正在运行
2.在html页面中写一下端代码,就可以进行调用
<html>
<head>
<title>通过ajax调用webservice</title>
<script>
var xhr='';
function sendAjaxWs(){
xhr=new ActiveXObject("Microsoft.XMLHTTP");
var wsurl="http://localhost:5084/hello?wsdl";
var requestbody='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" '+
' xmlns:q0="http://service.itcast.cn/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" '+
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
'<soapenv:Body><q0:sayHello><arg0>lisi</arg0></q0:sayHello></soapenv:Body></soapenv:Envelope>';
//打开链接
xhr.open("post",wsurl,true);
//设置请求
xhr.setRequestHeader("content-type","text/xml;charset=utf8");
//设置回调函数
xhr.onreadystatechange=_back;
//发送请求
xhr.send(requestbody);
}
//定义回调
function _back(){
if(xhr.readystate==4){
alert(xhr.status);
if(xhr.status==200){
var ret=xhr.responseXML;
var els= ret.getElementsByTagName("return");
alert(els[0].text);
}
}
}
</script>
</head>
<body>
<input type="button" οnclick="sendAjaxWs();" value="通过ajax调用webservice"/>
</body>
</html>