I want to add a web service to asp .net mvc application as a model any one has an idea how to do this ?
i wrote my web service:
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;
}
}
this web service must me invoked by android application
Any help ?