2017-03-04 35 views
0

我要路由我的API,通过这个URI网页API Attrbute路由URI问题

本地主机/ API/ServiceA/1234

其中ISBN = 1234

从URI目前我retriving JSON提到下面

本地主机/ 1234

其中1234 ISBN

我怎样才能得到相同的JSON结果与thte以下URI

本地主机/ API/ServiceA/1234

目前我收到上述网址

用下面的代码使用属性的路由我NUL得到的结果与

我有一个API Countroller

public class ServiceAController : ApiController 
    { 

     [Route("api/ServiceA/{isbn}")] 
     public Book GetBook(string isbn) 
      { 

      using (AppDbContext db = new AppDbContext()) 

      { 

       var query = from b in db.Books 

          where b.ISBN == isbn && b.Source == "Book Store 1" 

          select b; 

       return query.SingleOrDefault(); 

      } 

     } 
    } 
} 

回答

0

您似乎忘记保持[HTTPGET]属性为您的方法。

例如: [Route("api/ServiceA/{isbn}")] [HttpGet] public Book GetBook(string isbn){ //your implementation }