2

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?

2
  • For Android use GSON (Google's library for reading JSON), here is an awesome tutorial Commented Jul 9, 2012 at 2:15
  • looks like ASP.Net WebAPI would do the trick! Commented Jul 9, 2012 at 2:55

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.