http://www.codeproject.com/KB/webservices/aspwebsvr.aspx
Web Service
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Linq;
using System.Diagnostics;
using System.Configuration;
namespace MyWebService
{
/// <summary>
/// Summary description for Search
/// </summary>
[WebService(Namespace = "http://tempuri.org/ ")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Search : System.Web.Services.WebService
{
[WebMethod]
public string Add (int a, int b)
{
...
}
}
HTML + AJAX (IE)
<html>
<body>
<script language="javascript">
function btn_click ()
{
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//">";
note: from envykok
Add- web method name
http://tempuri.org - web method namesapce
sXml = sXml + "<a>"+ document.getElementById('a').value + "</a>";
sXml = sXml + "<b>"+ document.getElementById('b').value + "</b>";
sXml += "</Add></soap:Body></soap:Envelope>"
// Try to parse the XML string into DOM object
xmlObj.loadXML(sXml) ;
//To see the validated XML string is well-formed
document.getElementById('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 ;
}
</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" οnclick="jscript:btn_click()"></input>
</p>
<p>
Answer is <span id="answer"></span>
</p>
<hr/>
<p>
Request:</p>
<span id="XmlRequest"></span>
<p>Response:</p>
<span id="MyResult"></span>
</form>
</body>
</html>