asp.net 練習 js 調用webservice

來源:互聯網
上載者:User

標籤:blog   http   io   使用   java   ar   strong   for   div   

 

 

[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 

 

 

[html] view plaincopyprint? 
  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>  



 

asp.net 練習 js 調用webservice

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.