實踐檢驗,Visual Studio 2013頁是類似
在 Visual Studio 2012 中創建 ASP.Net Web Service,步驟非常簡單。如下:
第一步:創建一個“ASP.Net Empty Web Application”項目
創建一個“ASP.Net Empty Web Application”項目。你會看到一個進度條,顯示 Visual Studio 2012 正在創建這個空的 ASP.Net Web Application。
經歷短暫的等待之後,一個空的 ASP.Net Web Application 就建好了,它僅包含一個站點配製文件(Web.config),其餘的什麼也沒有。
第二步:在項目中添加“Web Service”新項目
在 Visual Studio 2012 的 Solution Explorer 中,選中當前的這個 project,添加新項目(右鍵菜單:Add --> New Item),選擇“Web Service”這種類型:
第三步:編碼、運行
添加完Web Service這種 new item 之後,Visual Studio 已經替我們寫了個示範的Web方法了:
直接按快捷鍵 F5 就可以看到結果:
點擊 HelloWorld 這個鏈接:
點擊頁面上的 Invoke 按鈕:
然後我們改寫這段代碼,添加我們自己的方法進去:
- namespace WebApplication1
- {
- using System.Web.Services;
- /// <summary>
- /// Summary description for WebService1
- /// </summary>
- [WebService(Namespace = "http://tempuri.org/")]
- public class WebService1 : System.Web.Services.WebService
- {
- [WebMethod]
- public string HelloWorld()
- {
- return "Hello World";
- }
- [WebMethod]
- public int Add(int x, int y)
- {
- return x + y;
- }
- }
- }
運行:
點擊 Add 鏈接,調用我們剛剛自己添加的 Add 函數:
點擊頁面上的 Invoke 按鈕,得到以 XML 格式返回的執行結果:
+
整個過程非常簡單、直觀。
參考:http://blog.csdn.net/yapingxin/article/details/7993989