zoukankan      html  css  js  c++  java
  • 使用HTTP GET访问方法

    •使用ScriptMethodAttribute进行标记
    –UseHttpGet属性设为true
    •客户端使用代理的方法没有任何变化
    •参数将使用QueryString进行传递
    •性能较HTTPPOST方法略有提高
    •一些特性略有改变
    –缓存的基础


    aspx
        <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>

    UseHttpGetService.asmx
    <%@ WebService Language="C#" Class="UseHttpGetService" %>

    using System;
    using System.Web;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.Web.Script.Services;

    [WebService(Namespace 
    = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo 
    = WsiProfiles.BasicProfile1_1)]
    [ScriptService]
    public class UseHttpGetService  : System.Web.Services.WebService
    {
        [WebMethod]
        
    public int GetRandom()
        {
            
    return new Random(DateTime.Now.Millisecond).Next();
        }

        [WebMethod]
        [ScriptMethod(UseHttpGet
    =true)]
        
    public int GetRangeRandom(int minValue, int maxValue)
        {
            
    return new Random(DateTime.Now.Millisecond).Next(minValue, maxValue);
        }
    }
    WebService方法加上    [ScriptMethod(UseHttpGet=true)]修饰即表示使用get的方法访问
  • 相关阅读:
    CF1202F You Are Given Some Letters...
    CF1178E Archaeology
    PTA (Advanced Level) 1005 Spell It Right
    PTA (Advanced Level) 1004 Counting Leaves
    Qt5——从零开始的Hello World教程(Qt Creator)
    PTA (Advanced Level) 1003 Emergency
    PTA (Advanced Level) 1002 A+B for Polynomials
    HDU 1272 小希的迷宫
    FZU 2150 Fire Game
    HihoCoder
  • 原文地址:https://www.cnblogs.com/timy/p/1178267.html
Copyright © 2011-2022 走看看