2016-10-26 41 views
1

我正在做一个Web API调用,我得到这个错误:HTTPGET属性必须为一个方法,但不是另一个

405 Method Not Allowed
The requested resource does not support http method 'GET'.

这里是呼叫:

var config = { 
     url: rootWebApiUrl + '/api/containerMove/allowMultipleBoxesPerMove', 
     method: 'GET' 
    }; 

    $http(config) 
     .then(function (response) { 
      // code here 
     }, function (response) { 
      // code here 
     }); 

如果我在HTTPGET属性添加到Web API方法,它的工作原理:

[HttpGet] 
[Route("api/containerMove/allowMultipleBoxesPerMove")] 
public bool AllowMultipleBoxesPerMove() 

我不明白的是,HttpGet不是NE用于在同一个Web API控制器上进行的其他调用。这里有一个,如果没有HttpGet属性适用于:

 var config = { 
      url: rootWebApiUrl + '/api/containerMove/getBatchRefreshInterval', 
      method: 'GET' 
     }; 

     $http(config) 

而且网页API方法:

[Route("api/containerMove/getBatchRefreshInterval")] 
public int GetBatchRefreshInterval() 

那么,为什么我需要HttpGet一个网页API方法而不是其他?这些调用和API方法几乎完全相同。

回答

5

Bob,Web API有一个约定优于配置的范例,因此,在这种情况下,名称以Get开头的所有操作都将被分配给HTTP Get,这就是得到 BatchRefreshInterval的原因不需要属性[HttpGet]

相关问题