2013-12-22 49 views
1

我正在尝试记录我的API。我已经写在我的控制器下面的代码(VB.NET):ApiDescriptions仅返回GET函数

Function Index() As ActionResult 
    Dim config = GlobalConfiguration.Configuration 
    Dim apiExplorer = config.Services.GetApiExplorer() 
    Dim apiDescs = apiExplorer.ApiDescriptions 
    Return View(apiExplorer) 
End Function 

问题是,当我调试我的代码,看是什么在apiDescs,我只能看到只有GET方法 - 我可以”没有看到任何DELETE,PUT甚至POST方法。这不是它应该如何工作。

这里是我的API的一个样本:

<HttpGet()> 
Public Function GetX(x as integer) as String 
'Code goes here 
End Function 

<HttpPost()> 
Public sub PostX(x as integer) 
'Code goes here 
End Function 

只有GetX是内ApiDescriptions返回无PostX。所有API中的所有POST,PUT和DELETE方法也是如此。

回答

0

我搜索了网页,但找不到我的答案或类似案例,所以既然我不确定我的项目到底发生了什么,我创建了一个新的MVC WebAPI项目,经检查发现一切正常,然后比较webconfig文件,它似乎我的项目并没有处理那些在<handlers>部分:

<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /> 
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /> 
<remove name="ExtensionlessUrlHandler-Integrated-4.0" /> 
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" /> 
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" /> 
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> 

加入他们我的项目运行良好,并ApiDescriptions现在列出了所有方法之后