asp.net AJAX Beta2 invoke some changes to the local webservice

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.