soap.js文件:
//web service 的发布地址
//此处为本地主机
var constURL="/myWS/9-01.asmx";
function getSOAP(){
var sendSoap = setPOSTSOAP();
var xmlHttpReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");
xmlHttpReq.open("POST",constURL, false);
//设置HTTP协议头信息
xmlHttpReq.setRequestHeader("Content-Type", "text/xml");
xmlHttpReq.setRequestHeader("Host", "localhost");
xmlHttpReq.setRequestHeader("content-length",sendSoap.length);
xmlHttpReq.setRequestHeader("SOAPAction", "http://localhost/Hello");
//发送SOAP请求
xmlHttpReq.send(sendSoap);
soap.innerText = xmlHttpReq.responseText
}
///组织生成用于请求的SOAP文件
function setPOSTSOAP(){
var strPostSoap = "";
strPostSoap += "<?xml version='1.0' encoding='utf-8'?>";
strPostSoap += "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>";
strPostSoap += " <soap:Body>";
strPostSoap += " <Hello xmlns='http://localhost'>";//localhost上的Hello函数原形Hello(string strName)
strPostSoap += " <strName>wang</strName>";// 参数值
strPostSoap += " </Hello>";
strPostSoap += " </soap:Body>";
strPostSoap += "</soap:Envelope>";
return strPostSoap;
}
=================================================
html测试文件源代码
<script src="soap.js"></script>
<a href="#" onclick="getSOAP();">get SOAP Message</a><br>
<div id = "soap"></div>