2013-12-22 46 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現在列出了所有方法之後