First, you only need to add a property [scriptmethod (usehttpget = true)] For WebService.
2. WebService
Using system;
Using system. Web;
Using system. collections;
Using system. Web. Services;
Using system. Web. Services. Protocols;
Using system. Web. Script. Services;
/// <Summary>
/// Summary of simplewebservice
/// </Summary>
[WebService (namespace = "http://tempuri.org/")]
[Webservicebinding (conformsto = wsiprofiles. basicprofile1_1)]
[Scriptservice]
Public class simplewebservice: system. Web. Services. WebService
{
Public simplewebservice ()
{
}
[Webmethod]
[Scriptmethod (usehttpget = true)]
Public int add (int A, int B)
{
Return A + B;
}
}
3 default. aspx
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.1 // en" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head id = "head1" runat = "server">
<Title> untitled page </title>
<Script language = "JavaScript" type = "text/JavaScript">
Function callservice (num1, num2)
{
Simplewebservice. Add (num1, num2, onsucceeded );
}
Function onsucceeded (result, context)
{
$ Get ("result"). innerhtml = result;
}
</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Asp: scriptmanager id = "scriptmanager1" runat = "server">
<Services>
<Asp: servicereference Path = "~ /Simplewebservice. asmx "/>
</Services>
</ASP: scriptmanager>
<Div id = "div1">
<Input id = "button1" type = "button" value = "3 plus 2" onclick = "callservice ('3', '2')"/>
<Div id = "result"> </div>
</Div>
</Form>
</Body>
</Html>