1

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 ?

Maha Mahmoud
  • 65
  • 1
  • 2
  • 5

1 Answers1

0

You can use asmx services here, please have a look at below link having same concern: Return Json Data from ASMX web service

It would better if you can use ASP.NET Web API as you want to send some JSON data to Andriod application. It would REST based and light weighted and will require less configurations needed.

Hope it would be helpful.

Community
  • 1
  • 1
Praveen Prajapati
  • 969
  • 1
  • 16
  • 21