1

Я создал проект веб-API asp.net, и я хочу сделать веб-сервис для доступа к этому api на разных платформах (мобильный, веб-сайт). Я новичок в веб-сервисах и должен научиться этому с нуля. Может ли кто-нибудь объяснить мне подробно весь процесс.Как создать веб-сервис для asp.net web api, построенный с использованием Entity Framework?

Мой веб-апи идет как:

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; 
    } 
} 
+0

Я предлагаю вам реализовать Restfull сервис –

+0

A "Web API" ** IS ** веб-сервис .... . –

+0

@marc_s как получить доступ к этой веб-апи с другой машины? – Prabhjot

ответ

0

Во-первых. Создайте свой веб-API в своем веб-приложении. для этой работы необходимо выполнить RestFul Служба (Get, Post, Put, Delete)
секунд. хоста вашего веб-приложения и базы данных в сервере

в мобильном приложении (напр. Xamarin)

С Web API Url получить ваши данные.

Пример:

Web Application

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

} 

In Your Mobile App Отправить запрос на этот адрес www.example.com/api/person/all/

После отправки запроса вы получите данные JSON, которые вы можете Ues его.

см.выше Ссылка:

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

 Смежные вопросы

  • Нет связанных вопросов^_^