//客户端代码
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Debug">
<Services>
<asp:ServiceReference Path="Services/UseHttpGetService.asmx" InlineScript="true" />
</Services>
</asp:ScriptManager>
<input type="button" value="Get Random" onclick="getRandom()" />
<input type="button" value="Get Range Random" onclick="getRandom(50, 100)" />
<script language="javascript" type="text/javascript">
function getRandom(minValue, maxValue)
{
if (arguments.length != 2)
{
UseHttpGetService.GetRandom(onSucceeded);
}
else
{
UseHttpGetService.GetRangeRandom(minValue, maxValue, onSucceeded);
}
}
function onSucceeded(result)
{
alert(result);
}
</script>
</form>
<asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Debug">
<Services>
<asp:ServiceReference Path="Services/UseHttpGetService.asmx" InlineScript="true" />
</Services>
</asp:ScriptManager>
<input type="button" value="Get Random" onclick="getRandom()" />
<input type="button" value="Get Range Random" onclick="getRandom(50, 100)" />
<script language="javascript" type="text/javascript">
function getRandom(minValue, maxValue)
{
if (arguments.length != 2)
{
UseHttpGetService.GetRandom(onSucceeded);
}
else
{
UseHttpGetService.GetRangeRandom(minValue, maxValue, onSucceeded);
}
}
function onSucceeded(result)
{
alert(result);
}
</script>
</form>
//WebService
[WebMethod]
public int GetRandom()
{
return new Random(DateTime.Now.Millisecond).Next();
}
[WebMethod]
//使用Get方式
[ScriptMethod(UseHttpGet=true)]
public int GetRangeRandom(int minValue, int maxValue)
{
return new Random(DateTime.Now.Millisecond).Next(minValue, maxValue);
}
public int GetRandom()
{
return new Random(DateTime.Now.Millisecond).Next();
}
[WebMethod]
//使用Get方式
[ScriptMethod(UseHttpGet=true)]
public int GetRangeRandom(int minValue, int maxValue)
{
return new Random(DateTime.Now.Millisecond).Next(minValue, maxValue);
}
浙公网安备 33010602011771号