1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
<script type="text/javascript" language="javascript">
// variables
var strMethodName;
var strSoapContent;
var soapAction;
var url;
var data;
var xmlhttp ;
//var strSoapContent;
//Function to create parameter for WebService method.function
function createWSParam()
{
strMethodName = 'HelloWorld' ;
//var strSoapContent = '<countryName>' + count4WSCall + '</ countryName >\n' + '<boolAsync>' + strCountryName + '</ boolAsync >\n';
strSoapContent = "" ;
}
//Function to create SOAP data packet.function
function createSOAPData(strMethodName, strSoapContent)
{
soapAction = 'http://tempuri.org/' + strMethodName ;
url = 'http://localhost:1329/MonService/MonService.asmx' ;
data = '<?xml version=\'1.0\' encoding=\'utf-8\'?>\n'
+'<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/\'>\n'
+ '<soap:Body>\n'
+ '<' + strMethodName + ' xmlns=\'http://tempuri.org/\'>\n'
+ strSoapContent
+ '</' + strMethodName + '>\n'
+ '</soap:Body>\n'
+ '</soap:Envelope>';
}
//Function to create XMLHttpRequest.function
function getXmlHttpObject()
{
if(window.ActiveXObject)
{
try
{
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
}
catch (ex)
{
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
}
else if (window.XMLHttpRequest) //For Non-IE
{
xmlhttp = new XMLHttpRequest();
}
}
//Function to send the SOAP Request.function
function sendSOAPDataToWebService(xmlhttp, url, data, soapAction)
{
xmlhttp.open('POST', url, true);
xmlhttp.onreadystatechange = processgetSOAPResponseData ;
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.setRequestHeader('SOAPAction', soapAction);
xmlhttp.send(data);
}
//Function to process the SOAP Response.function
function processgetSOAPResponseData()
{
if (xmlhttp.readyState == 4)
{
if (xmlhttp.status == 200) // only if "OK"
{
try
{
if (window.ActiveXObject) // code for IE
{
doc = new ActiveXObject("Microsoft.XMLDOM");
doc.async="false";
doc.loadXML(xmlhttp.responseText);
}
else // code for Mozilla, Firefox, Opera, etc.
{
var parser=new DOMParser();
doc = parser.parseFromString(xmlhttp.responseText,"text/xml");
}
var rootNode = doc.documentElement; // documentElement always represents the root node
alert("message : " + rootNode)
/*
if( rootNode.childNodes[0].childNodes[0].childNodes[0].nodeName == "getCurrentPositionDataResult" )
{
//Method to process the SOAP data
getCurrentPositionData(rootNode) ;
}
*/
}
catch (ex){}
}
}
}
// main
function init()
{
createWSParam();
createSOAPData(strMethodName, strSoapContent);
getXmlHttpObject();
sendSOAPDataToWebService(xmlhttp, url, data, soapAction);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body onload="init()">
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html> |
Partager