found that the latest version of the changes are very large, below the test situation for a description (here to borrow the official example):
1, first build a WebService file (helloworldservice.asmx), the code is as follows:
<%@ WebService language= "C #" class= "Samples.AspNet.HelloWorldService"%>
Using System;
Using System.Web;
Using System.Web.Services;
Using System.Xml;
Using System.Web.Services.Protocols;
Using Microsoft.Web.Script.Services;
Namespace Samples.aspnet
{
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = wsiprofiles.basicprofile1_1)]
[ScriptService]
public class HelloWorldService:System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld (string query)
{
String inputstring = Server.HTMLEncode (query);
if (! String.IsNullOrEmpty (inputstring))
{
Return String.Format ("Hello, your queried for {0}.") The "
+ "Current time is {1}", InputString, DateTime.Now);
}
Else
{
Return "The query string is null or empty";
}
}
}
}
Here to explain the [ScriptService] attribute, only the addition of this property, in order to be in the page through JS asynchronous call;
2, build a call page (ajaxscript1.aspx), as follows:
<%@ Page language= "C #"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title= "Test One"/>
<style type= "Text/css" >
Body {font:11pt trebuchet MS;
Font-color: #000000;
padding-top:72px;
Text-align:center}
. text {font:8pt Trebuchet MS}
</style>
<body>
<form id= "Form1" runat= "Server" >
<asp:scriptmanager runat= "Server" id= "ScriptManager" >
<Services>
<asp:servicereference path= "~/helloworldservice.asmx"/>
</Services>
</asp:ScriptManager>
<div>
Search for
<input id= "Searchkey" type= "text"/>
<input id= "SearchButton" type= "button" value= "Search"
Onclick= "Dosearch ()"/>
</div>
</form>
<div>
<span id= "Results" ></span>
</div>
<script type= "Text/javascript" >
function Dosearch ()
{
var Srchelem = document.getElementById ("Searchkey");
Samples.AspNet.HelloWorldService.HelloWorld (Srchelem.value, onrequestcomplete);
}
function Onrequestcomplete (Result)
{
var Rsltelem = document.getElementById ("Results");
rsltelem.innerhtml = result;
}
</script>
</body>
Note that here's <asp:scriptmanager runat= "server" id= "ScriptManager" >
<Services>
<asp:servicereference path= "~/helloworldservice.asmx"/>
</Services>
</asp:ScriptManager>
Put it in the <form>.
Change seems to be very big!