• asp.net 练习 js 调用webservice


    [csharp] view plaincopyprint?
     
    1. using System;  
    2. using System.Collections.Generic;  
    3. using System.Linq;  
    4. using System.Web;  
    5. using System.Web.Services;  
    6.   
    7. /// <summary>  
    8. ///JsWebServiceTest 的摘要说明  
    9. /// </summary>  
    10. [WebService(Namespace = "http://tempuri.org/")]  
    11. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]  
    12. //若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。   
    13. [System.Web.Script.Services.ScriptService]  
    14. public class JsWebServiceTest : System.Web.Services.WebService {  
    15.   
    16.     public JsWebServiceTest () {  
    17.   
    18.         //如果使用设计的组件,请取消注释以下行   
    19.         //InitializeComponent();   
    20.     }  
    21.   
    22.     [WebMethod]  
    23.     public string HelloWorld() {  
    24.         return "Hello World";  
    25.     }  
    26.   
    27.     [WebMethod]  
    28.     public string WelCome(string name)  
    29.     {  
    30.         return name+":欢迎光临";  
    31.     }  
    32.       
    33. }  

    注意事项  js调用webservice 方法 要取消注释  system.web.script.services.scriptservice 

    1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebServiceForm2.aspx.cs" Inherits="test2_WebServiceForm2" %>  
    2.   
    3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    4.   
    5. <html xmlns="http://www.w3.org/1999/xhtml">  
    6. <head runat="server">  
    7.     <title></title>  
    8. </head>  
    9. <body>  
    10.     <form id="form1" runat="server">  
    11.     <div>  
    12.         <asp:ScriptManager ID="ScriptManager1" runat="server">  
    13.         <!--引用web 服务 -->  
    14.             <Services>  
    15.             <asp:ServiceReference  Path="~/WebService/JsWebServiceTest.asmx"/>  
    16.             </Services>  
    17.         </asp:ScriptManager>  
    18.         <input type="button" value="查看" onclick="jsCallWeb();" />  
    19.         <br />  
    20.         <input type="button" value="查看2" onclick="jsCallWeb2();" />  
    21.     </div>  
    22.     </form>  
    23. </body>  
    24. </html>  
    25. <script type="text/javascript">  
    26.     //调用1  
    27.     function jsCallWeb() {  
    28.         JsWebServiceTest.HelloWorld(outResult);  
    29.     }  
    30.     //调用2  
    31.     function jsCallWeb2() {  
    32.         JsWebServiceTest.WelCome('kevin', outResult);  
    33.     }  
    34.     //输出结果  
    35.     function outResult(result) {  
    36.         alert(result);  
    37.     }  
    38.   
    39. </script>  



  • 相关阅读:
    loadrunne-- Analysis 分析器
    Fiddler抓包工具详细介绍
    在 Windows 10 x64 上安装及使用 ab 工具的流程
    Ab工具基本使用
    ab压测返回结果解析
    VMware Workstation 14 Pro永久激活密钥
    通用接口测试用例设计
    线段树の二 区间乘+区间加
    线段树の一 区间和
    C++位运算
  • 原文地址:https://www.cnblogs.com/ranran/p/3974901.html
Copyright © 2020-2023  润新知