Click here to Skip to main content
12,951,983 members (66,130 online)
Rate this:
Please Sign up or sign in to vote.

I want to call web service from (javascript html) code, i tried lots of links,
but its not working in my case, i have a very simple web service running on[^] which return hello world. if somebody can use same link and give me output using (javascript and html), it will be greatly helpfull for me.

Thanks in advance
Posted 12-Dec-12 18:52pm
Updated 12-Dec-12 18:54pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

<script language="javascript" type="text/javascript">
var soapHeader = '<?xml version="1.0" encoding="utf-8"?>'
soapHeader += '<soap:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap="">'
soapHeader += '<soap:Body><HelloWorld xmlns="" /></soap:Body></soap:Envelope>'
//the url of Webservice
var postUrl = 'http://localhost:4174/TestWeb/WebService.asmx';

var soapActionUrl = '';

var xmlhttp = null;
try {
xmlhttp = new XMLHttpRequest();
}catch (e) {xmlhttp = false; }
try {
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
}catch (e) { xmlhttp = false; }
try {
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');}catch (e) { xmlhttp = false; }
if( xmlhttp )
{ ('POST', postUrl, true);
xmlhttp.onreadystatechange = function()
if( xmlhttp.readyState == 4 )

xmlhttp.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');

xmlhttp.setRequestHeader("Host", "localhost");
xmlhttp.setRequestHeader("SOAPAction", soapActionUrl); xmlhttp.setRequestHeader("Content-Length", soapHeader.length );


Nice article you can fallow this Invoking WebServices using JavaScript[^]
sunil_mali 13-Dec-12 6:42am
hi friend,

i have tried your code, but this code is only working in ie, i am developing this solution to work on mobile and there are very less mobiles which has internet explorer inbuilt.
I think problem is with .htc file which you have provided with your code.
Do you have any other solution, your solution didn't worked for me as it works only on ie, and it was too complecated.

Calling Web Services from HTML Pages using JavaScript[^]

i checked above link, and it helped me a lot to run this solution
but i should make it run on all browsers because my application is mobile based.
can we do same think without .htc file?
do u have any other solution for same?
will it work on all devices and all browser?
Suvabrata Roy 13-Dec-12 7:41am
Try this
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

ha ha...
finally i found it...
i used jquery to retrieve my data....
    <title>Calling Web Service from jQuery</title>
    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#btnCallWebService").click(function (event) {
                var wsUrl = "";
                var soapRequest =
'<?xml version="1.0" encoding="utf-8"?> \
<soap:Envelope xmlns:xsi="" \
    xmlns:xsd="" \
    xmlns:soap=""> \
  <soap:Body> \
    <Hello xmlns=""> \
      <name>' + $("#txtName").val() + '</name> \
    </Hello> \
  </soap:Body> \
                    type: "POST",
                    url: wsUrl,
                    contentType: "text/xml",
                    dataType: "xml",
                    data: soapRequest,
                    success: processSuccess,
                    error: processError
        function processSuccess(data, status, req) {
            if (status == "success")
        function processError(data, status, req) {
            alert(req.responseText + " " + status);
        Calling Web Services with jQuery/AJAX
    Enter your name:
    <input id="txtName" type="text" />
    <input id="btnCallWebService" value="Call web service" type="button" />
    <div id="response" />
raaz.rbs 7-Nov-13 11:48am
this solution is not working with Google Chrome!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,239
CHill60 3,490
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,880

Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 15 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100