How to make a web service for asp.net web api built using Entity Framework?

123 Views Asked by At

I have built an asp.net Web API project and I want to make a web service to access this api on different platforms (mobile, web). I am new to web services and have to learn it from scratch. Can anyone explain me in detail the whole process.

My web api goes like:

namespace EUClientVisitAPI.Controllers
{
    [RoutePrefix("api/Event")]
    public class EventController : ApiController
    {
        private EUClientVisitEntities db = new EUClientVisitEntities();

        // GET: api/Event
        public IQueryable Gettb_Event()
        {
             db.Configuration.ProxyCreationEnabled = false;         

             var eventDetails = (from e in db.tb_Event
                                 select new
                                      {
                                          e.EventID,
                                          e.tb_Customer.CustomerName,
                                          e.StartDate,
                                          e.EndDate,
                                          loc = (from l in db.tb_EventLocation where l.EventID == e.EventID select new { l.tb_Location.LocationName }).Distinct(),
                                          e.Objective
                                      });

            return (IQueryable)eventDetails;
    }     

    [Route("EventDetails")]
    public IQueryable GetEventDetails()
    {
        db.Configuration.ProxyCreationEnabled = false;

        var customerList = (from c in db.tb_Customer
                            join e in db.tb_Event
                            on c.CustomerID equals e.CustomerID
                            join el in db.tb_EventLocation
                            on e.EventID equals el.EventID
                            select  new
                            {
                                 el.LocationID
                            }).Distinct();

        return (IQueryable)customerList;
    }
}
1

There are 1 best solutions below

0
On

First. create your Web API In The your Web Application. for this work you must implement RestFul Service(Get,Post,Put,Delete)
second. Host Your Web Application and database in server

in the your Mobile App(ex. Xamarin )

With Web API Url Get Your Data.

Example:

Web Application

[RoutePrefix("api/person")]
public class PrsonApiController : ApiController
{ 
  [httpGet]
  [Route("Person/all")]
  public  IHttpActionResult Get()
  {
    return context.Person.ToList();
  }

}

In Your Mobile App Send request to this Url www.example.com/api/person/all/

After send request you get Json data that you can ues it.

see above Link :

Using HTTP Methods (GET, POST, PUT, etc.) in Web API

Calling Web API from a Windows Phone 8 Application

Building Web APIs for Mobile Apps Using ASP.NET Web API 2.1