百度空间 | 百度首页 
 
查看文章
 
通过XMLHTTPRequest对象调用Web Service
2007年11月16日 星期五 17:39

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>


类别:默认分类 | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu