I made application in ASP.NET MVC3 and I want to connect application with Android.
So first step is to make Web Service, that will communicate with Android.
But I'm new in this area and I don't know how to start.
Does anyone have some tutorial for making Web Service for ASP.NET MVC3 application?
Also I need instructions for connecting Android with that Web Service?
-
For Android use GSON (Google's library for reading JSON), here is an awesome tutorialBojan Kogoj– Bojan Kogoj2012-07-09 02:15:46 +00:00Commented Jul 9, 2012 at 2:15
-
looks like ASP.Net WebAPI would do the trick!Yusubov– Yusubov2012-07-09 02:55:16 +00:00Commented Jul 9, 2012 at 2:55
Add a comment
|
1 Answer
You really have two questions here, and unfortunately the Android one is a little too broad to answer quickly. So... let's tackle your first question.
In MVC it is pretty easy to create a simple web service. Create a controller and return JSON from it:
public class PersonController: Controller{
public JsonResult Index(){
var personList = GetFromDB();
return Json(personList, JsonRequestBehavior.AllowGet);
}
[HttpPost, ActionName("Index")]
public JsonResult CreatePerson(Person newPerson){
var insertedPerson = InsertIntoDB(newPerson);
return Json(insertedPerson);
}
}
Now, with the default routing in place you can simply call those methods with the following URL, and the appropriate HTTP Verb.
http://www.mydomain.com/person
However, it may be worth mentioning this is far easier to do using ASP.Net WebAPI.