2015-04-01 46 views
0
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Services; 

/// <summary> 
/// Summary description for WebService 
/// </summary> 
[WebService(Namespace = "http://tempuri.org/")] 
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService] 
public class WebService : System.Web.Services.WebService { 

    public WebService() { 

     //Uncomment the following line if using designed components 
     //InitializeComponent(); 
    } 
    public string FirstName { get; set; } 
    public string LastName { get; set; } 

    [WebMethod] 
    public string HelloWorld() { 
     return "Hello World"; 
    } 
} 

如何在asp.net中使用webservice創建angularjs的示例?
如何在angularjs中創建webservice?使用Webservice的AngularJS

我已經創建了一個簡單的angularjs示例,但是如何創建一個angularjs Webservice?

+0

這是什麼代碼? – sakura 2015-04-01 12:36:25

+0

你可以使用Web.Api嗎? – Lev 2015-05-28 14:50:56

回答

1

您可以創建一個WCF服務並在AngularJS應用程序中使用它。

  1. 創建一個返回JSON數據的WCF服務。
  2. 在IIS上託管它。
  3. 創建一個AngularJS應用程序。
  4. 在AngularJS應用程序中使用WCF服務。

This and this鏈接是您想要做的簡單示例。