我想向 asp .net mvc 应用程序添加一个 Web 服务作为模型,任何人都知道如何做到这一点?
我写了我的网络服务:
public class WebService : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[HttpPost]
[WebMethod(EnableSession = true)]
public string GetData(IDictionary<string, string> inputParam)
{
MusicStoreEntities db = new MusicStoreEntities();
List<Category> categoriesList = new List<Category>();
List<Song> songsList = new List<Song>();
String sJSON = " ";
int ID = 0 ;
if (inputParam.ContainsKey("categoryId") ){
ID = Int32.Parse(inputParam["categoryId"]);
}
if (ID == 0)
{
categoriesList = db.Albums.ToList();
var oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
sJSON = oSerializer.Serialize(categoriesList);
}
else {
songsList = db.SongList.Where(d => d.categoryId == ID).ToList();
var oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
sJSON = oSerializer.Serialize(songsList);
}
return sJSON;
}
}
我必须由 android 应用程序调用此 Web 服务
有什么帮助吗?