JAVASCRIPT调用WEBSERVICE

来源:互联网 发布:vivian maire 知乎 编辑:程序博客网 时间:2024/06/06 07:00

HTML端代码

<html>
 <header>
  <script type="text/javascript">
   function CallWeb(){
    var inputStr = document.getElementById('input').value;
    var postUrl = 'http://localhost:21451/Service1.asmx';
    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    var postData = '<?xml version="1.0" encoding="utf-8"?>';
    postData = postData + '<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">';
    postData = postData + '<soap12:Body>';
    postData = postData + '<HelloWorld xmlns="http://tempuri.org/">';
    postData = postData + '<s>' + inputStr + '</s>';
    postData = postData + '</HelloWorld>';
    postData = postData + '</soap12:Body>';
    postData = postData + '</soap12:Envelope>';
    xmlhttp.Open('POST', postUrl, false);
    xmlhttp.SetRequestHeader('Content-Type', 'application/soap+xml');
    xmlhttp.Send(postData);
    var OutLabel = document.getElementById('output');
    OutLabel.value = xmlhttp.responseText;
   }
  </script>
 </header>
 <body>
  <input type='textbox' id='input'/>
  <input type='button' value='调用web服务' onclick = 'CallWeb()'/>
  <input type='textbox' id='output'/>
 </body>
</html>

0 0
原创粉丝点击