Here is the web service link: Currency Convertor
<html>
<head>
<script type="text/javascript">
function WebSvc()
{
WebSvc.prototype.CallWebService = function(url, soapXml, callback)
{
var xmlDoc = null;
if (window.XMLHttpRequest)
{
xmlDoc = new XMLHttpRequest(); //Newer browsers
}
else if (window.ActiveXObject) //IE 5, 6
{
xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlDoc)
{
//callback for readystate when it returns
var self = this;
xmlDoc.onreadystatechange = function() { self.StateChange(xmlDoc, callback); };
//set up the soap xml web service call
xmlDoc.open("POST", url, true);
xmlDoc.setRequestHeader("Content-Type", "text/xml");
xmlDoc.setRequestHeader("Content-Length", soapXml.length);
xmlDoc.send(soapXml);
}
else
{
if (callback)
{
callback(false, "unable to create XMLHttpRequest object");
}
}
};
WebSvc.prototype.StateChange = function(xmlDoc, callback)
{
if (xmlDoc.readyState === 4)
{
var text = "";
if (xmlDoc.status === 200)
{
text = xmlDoc.responseText;
}
if (callback !== null)
{
callback(xmlDoc.status === 200, text);
}
}
};
}
function callComplete(result, data)
{
if (result)
{
document.getElementById("res").innerHTML=getTagValue(data, "ConversionRateResult");
}
else
{
alert("Error occurred calling web service.");
}
}
function getTagValue(inputStr, tagName)
{
var stag = "<" + tagName + ">";
var etag = "</" + tagName + ">";
var startPos = inputStr.indexOf(stag, 0);
if (startPos >= 0)
{
var endPos = inputStr.indexOf(etag, startPos);
if (endPos > startPos)
{
startPos = startPos + stag.length;
return inputStr.substring(startPos, endPos);
}
}
return "";
}
function getTime()
{
var soap = createSoapHeader();
var webServiceCall = new WebSvc();
webServiceCall.CallWebService("http://www.webservicex.net/CurrencyConvertor.asmx?wsdl",soap, callComplete);
}
function createSoapHeader()
{
var soap = "<soapenv:Envelope xmlns:soapenv="+"\"http://schemas.xmlsoap.org/soap/envelope/\""+" xmlns:web="+"\"http://www.webserviceX.NET/\""+"><soapenv:Header/><soapenv:Body><web:ConversionRate><web:FromCurrency>USD</web:FromCurrency><web:ToCurrency>INR</web:ToCurrency></web:ConversionRate></soapenv:Body></soapenv:Envelope>";
return soap;
}
</script>
</head>
<body>
<button type="button" onclick="getTime()">Click Me</button>
<div id="res"></div>
</body>
</html>
HTML code:
<html>
<head>
<script type="text/javascript">
function WebSvc()
{
WebSvc.prototype.CallWebService = function(url, soapXml, callback)
{
var xmlDoc = null;
if (window.XMLHttpRequest)
{
xmlDoc = new XMLHttpRequest(); //Newer browsers
}
else if (window.ActiveXObject) //IE 5, 6
{
xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlDoc)
{
//callback for readystate when it returns
var self = this;
xmlDoc.onreadystatechange = function() { self.StateChange(xmlDoc, callback); };
//set up the soap xml web service call
xmlDoc.open("POST", url, true);
xmlDoc.setRequestHeader("Content-Type", "text/xml");
xmlDoc.setRequestHeader("Content-Length", soapXml.length);
xmlDoc.send(soapXml);
}
else
{
if (callback)
{
callback(false, "unable to create XMLHttpRequest object");
}
}
};
WebSvc.prototype.StateChange = function(xmlDoc, callback)
{
if (xmlDoc.readyState === 4)
{
var text = "";
if (xmlDoc.status === 200)
{
text = xmlDoc.responseText;
}
if (callback !== null)
{
callback(xmlDoc.status === 200, text);
}
}
};
}
function callComplete(result, data)
{
if (result)
{
document.getElementById("res").innerHTML=getTagValue(data, "ConversionRateResult");
}
else
{
alert("Error occurred calling web service.");
}
}
function getTagValue(inputStr, tagName)
{
var stag = "<" + tagName + ">";
var etag = "</" + tagName + ">";
var startPos = inputStr.indexOf(stag, 0);
if (startPos >= 0)
{
var endPos = inputStr.indexOf(etag, startPos);
if (endPos > startPos)
{
startPos = startPos + stag.length;
return inputStr.substring(startPos, endPos);
}
}
return "";
}
function getTime()
{
var soap = createSoapHeader();
var webServiceCall = new WebSvc();
webServiceCall.CallWebService("http://www.webservicex.net/CurrencyConvertor.asmx?wsdl",soap, callComplete);
}
function createSoapHeader()
{
var soap = "<soapenv:Envelope xmlns:soapenv="+"\"http://schemas.xmlsoap.org/soap/envelope/\""+" xmlns:web="+"\"http://www.webserviceX.NET/\""+"><soapenv:Header/><soapenv:Body><web:ConversionRate><web:FromCurrency>USD</web:FromCurrency><web:ToCurrency>INR</web:ToCurrency></web:ConversionRate></soapenv:Body></soapenv:Envelope>";
return soap;
}
</script>
</head>
<body>
<button type="button" onclick="getTime()">Click Me</button>
<div id="res"></div>
</body>
</html>
can you tell me coding of getTime()
ReplyDeletein c#