自强不息,止于至善

身无半文,心忧天下;手释万卷,神交古人
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

客户端模拟方法重载

Posted on 2007-10-28 09:08  L.Zhang  阅读(146)  评论(0)    收藏  举报

//客户端脚本

    <asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Debug">
            
<Services>
                
<asp:ServiceReference Path="WebServiceFoundation.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)
                {
                    Sample.WebServiceFoundation.GetRandom(getRandomSucceeded);
                }
                
else
                {
                    Sample.WebServiceFoundation.GetRangeRandom(minValue, maxValue, getRandomSucceeded);
                }
            }
            
            
function getRandomSucceeded(result)
            {
                alert(result);
            }
        
</script>
//WebService
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo 
= WsiProfiles.BasicProfile1_1)]
    [ScriptService]
    
public class WebServiceFoundation : System.Web.Services.WebService
    {
        [WebMethod]
        
public int GetRandom()
        {
            
return new Random(DateTime.Now.Millisecond).Next();
        }

        [WebMethod]
        
public int GetRangeRandom(int minValue, int maxValue)
        {
            
return new Random(DateTime.Now.Millisecond).Next(minValue, maxValue);
        }
    }