Services属性
Services用来管理对WebService的调用,通过<asp:ServiceReference>标签可以在Services中注册一个WebService,在运行时ScriptManager将为每一个ServiceReference对象生成一个客户端代理,<asp:ServiceReference>标签一个很重要的属性是Path,用来指定WebService的路径,如下所示:
< Services >
< asp:ServiceReference Path ="Service.asmx" />
</ Services >
</ asp:ScriptManager >
看一个简单的调用WebService的例子:
WebService如下,注意在WebServiceSample上加ScriptService特性:页面:
public class WebServiceSample : System.Web.Services.WebService {
public WebServiceSample()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string EchoString(String s)
{
return "Hello " + s;
}
}
ASPX
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head runat ="server" >
< title > Untitled Page </ title >
</ head >
< script type ="text/javascript" language ="JavaScript" >
function OnbuttonGo_click()
{
requestSimpleService = WebServiceSample.EchoString(
document.getElementById('inputName').value, //params
OnRequestComplete //Complete event
);
return false;
}
function OnRequestComplete(result)
{
alert(result);
}
</ script >
< body >
< form id ="form1" runat ="server" >
< asp:ScriptManager ID ="ScriptManager1" runat ="server" >
< Services >
< asp:ServiceReference Path ="WebServiceSample.asmx" />
</ Services >
</ asp:ScriptManager >
< div >
< input type ="text" id ="inputName" size =20 />
< input id ="button" type ="button" value ="调 用" onclick ="return OnbuttonGo_click()" /></ div >
</ form >
</ body >
</ html >
运行后效果如下:
当然了也可以在运行时动态的在Services中加入ServiceReference,下面看一个运行时动态加入ServiceReference的例子:
< script runat ="server" >
void Page_Load(object sender, EventArgs e)
{
ServiceReference sr = new ServiceReference();
sr.Path = "WebServiceSample.asmx";
ScriptManager1.Services.Add(sr);
}
</ script >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head runat ="server" >
< title > Untitled Page </ title >
</ head >
< script type ="text/javascript" language ="JavaScript" >
function OnbuttonGo_click()
{
requestSimpleService = WebServiceSample.EchoString(
document.getElementById('inputName').value, //params
OnRequestComplete //Complete event
);
return false;
}
function OnRequestComplete(result)
{
alert(result);
}
</ script >
< body >
< form id ="form1" runat ="server" >
< asp:ScriptManager ID ="ScriptManager1" runat ="server" >
</ asp:ScriptManager >
< div >
< input type ="text" id ="inputName" size =20 />
< input id ="button" type ="button" value ="调 用" onclick ="return OnbuttonGo_click()" /></ div >
</ form >
</ body >
</ html >
可以看到运行后和在ScriptManager中直接加入的效果是一样的。
六.Scripts属性
关于Scripts属性到后面具体再说吧,最主要的属性有Path指定脚本的路径,ScriptMode指定客户端脚本的模式,它会覆盖ScriptManager中的ScriptMode属性,还有一个属性是IgnoreScriptPath,指定是否忽略掉ScriptManager中的ScriptPath属性。
关于ScriptManager控件就学习到这里了,至于AuthenticationService属性和ProfileService属性都很简单。
link