Click here to Skip to main content
12,501,882 members (47,972 online)
Click here to Skip to main content

Stats

1.1M views
18.6K downloads
174 bookmarked
Posted

ASP.NET Web Service

, 7 Jul 2001 CPOL
Tutorial on Creating ASP.NET Web Service
<html>
<body>
<script language="jscript">
        function btn_click (a, b)
        {
                var xmlObj = new ActiveXObject("Msxml2.DOMDocument") ;
                var sXml  = "<?xml version=\"1.0\" ?>" ;
                      sXml += "<soap:Envelope "
                      sXml += "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " ;
                      sXml += "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " ;
                      sXml += "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" ;
                      sXml += "<soap:Body>" ;
                      sXml += "<Add xmlns=\"http://tempuri.org/\">" ;
                      sXml = sXml + "<a>" + a.value  + "</a>" ;
                      sXml = sXml + "<b>" + b.value  + "</b>" ;                      
                      sXml += "</Add></soap:Body></soap:Envelope>"
                
                xmlObj.loadXML(sXml) ;
                
                XmlRequest.innerText =  xmlObj.xml  ;
                
                var xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP") ;
                xmlHTTP.Open ( "Post", "http://localhost/ASP.NET/MyWebService.asmx", false) ;
                xmlHTTP.setRequestHeader("SOAPAction", "http://tempuri.org/Add") ;
                xmlHTTP.setRequestHeader("Content-Type", "text/xml; charset=utf-8" ) ;
                xmlHTTP.Send(xmlObj.xml) ;
                MyResult.innerText =  xmlHTTP.responseText ;
                
                var xmlResponse = xmlHTTP.responseXML ;
                answer.innerText = xmlResponse.selectSingleNode("soap:Envelope/soap:Body/AddResponse/AddResult").text ;
        }

</script>


<form>
        <p>Please input a:<input id="a" name="a"></input></p>
        <p>Please input b:<input id="b" name="b"></input></p> 
        <p>
        <input type="button" id="btn"  value="Enter" 
                onclick="jscript:btn_click(a, b)"></input>
        </p>
        <p>Answer is <span id="answer"></span></p>
        <hr></hr>
        <p>Request:</p>
        <span id="XmlRequest"></span>
        <p>Response:</p>        
        <span id="MyResult"></span>
        
</form>

</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

Share

About the Author

matthew_from_hk
Founder
Hong Kong Hong Kong
I am always interested in finding innovative ways for building better applications and founded a technology company since 2003. Welcome to exchange any idea with you and if I am not too busy before deadline of projects, I will reply your emails. Also, if you willing to pay for consulting works and customized software development, you can leave me message.

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160919.1 | Last Updated 8 Jul 2001
Article Copyright 2001 by matthew_from_hk
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid