简体   繁体   English

为什么WebApi帮助页面中没有显示操作

[英]Why aren't actions showing in WebApi Help Page

I have a WebApi project in Visual Studio 2012. I created it from the template and have since added in the HelpPage stuff through the use of NuGet. 我在Visual Studio 2012中有一个WebApi项目。我是从模板创建的,然后通过使用NuGet添加到HelpPage中。 Below is my example. 以下是我的例子。

HierarchyController.cs HierarchyController.cs

public class HierarchyController : ApiController
{
    [ActionName("DefaultAction")]
    public List<Hierarchy> Get([FromUri]List<Guid> guid)
    {...}

    [HttpGet]
    public List<Hierarchy> Children([FromUri]List<Guid> guid)
    {...}

    [HttpGet]
    public List<Hierarchy> Descendants([FromUri]List<Guid> guid)
    {...}

    [ActionName("DefaultAction")]
    public HttpResponseMessage Post([FromBody]List<Hierarchy> hierarchies)
    {...}

    [ActionName("DefaultAction")]
    public HttpResponseMessage Delete([FromUri]List<Guid> guid)
    {...}
}

WebApiConfig.cs WebApiConfig.cs

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        config.Routes.MapHttpRoute(
            name: "ActionApi",
            routeTemplate: "api/{controller}/{action}/{guid}"
        );
        config.Routes.MapHttpRoute(
            name: "GuidApi",
            routeTemplate: "api/{controller}/{guid}",
            defaults: new { action = "DefaultAction", guid = RouteParameter.Optional }
        );
    }
}

Result from .../help 来自... / help的结果

Hierarchy 等级制度

API--------------------------Description API --------------------------说明

GET api/Hierarchy-------Gets Hierarchy(s) by guid(s) GET api / Hierarchy -------通过guid获取层次结构

POST api/Hierarchy-----No documentation available. POST api / Hierarchy -----没有可用的文档。

DELETE api/Hierarchy--Deletes Hierarchy(s) DELETE api / Hierarchy - 删除层次结构

both of the "action" functions are missing from the help page. 帮助页面中缺少这两个“操作”功能。 Any idea what I'm missing? 知道我错过了什么吗?

Also, everything does actually function correctly, the help page displaying everything is the only problem. 此外,一切确实正常运行,显示一切的帮助页面是唯一的问题。

Sub Question: 子问题:

Also a secondary question I have defined xml comments for each of the functions such as 另外一个问题我已经为每个函数定义了xml注释,例如

/// <summary>
/// Deletes Hierarchy(s)
/// </summary>
/// <param name="guid">List of Hierarchies</param>
/// <returns>HttpResponseMessage</returns>

They were all auto generated in VS2012 by typing /// then just filling out the sections, but help page section for the Post always says "No documentation available." 它们都是在VS2012中自动生成的,方法是键入///然后填写各个部分,但是Post的帮助页面部分总是说“没有可用的文档”。 Is this because I haven't fixed the problem that shows up under the application/x-www-form-urlencoded tab (Cannot use formmater 'JQueryMvcFormUrlEncodedFormatter' error)? 这是因为我没有解决在application/x-www-form-urlencoded选项卡下显示的问题(不能使用formmater'JQueryMvcFormUrlEncodedFormatter'错误)?

Regarding the 1st question: 关于第一个问题:
List<Guid> even though decorated with FromUri cannot be model bound as you might be expecting. List<Guid>即使用FromUri修饰也不能像你期望的那样受到模型限制。 This was a bug which was fixed recently and I think you are using the previous release bits and hence might not be able to see this. 这是一个最近修复的错误,我认为你正在使用以前的版本位,因此可能无法看到这个。 You can see what i mean by changing all the occurrences of [FromUri]List<Guid> guid with let's say string guid . 你可以通过改变[FromUri]List<Guid> guid所有出现来看看我的意思,让我们说string guid You should now be seeing all the routes in help page. 您现在应该在帮助页面中看到所有路线。 By the way, ApiExplorer explorers each route and for each route it explores all reachable controllers from that route. 顺便说一句,ApiExplorer探索每条路线,并为每条路线探索该路线上所有可到达的控制器。 So, the results you would be seeing could be surprising, but are correct...just fyi. 所以,你会看到的结果可能会令人惊讶,但是正确的......只是fyi。

Regarding 2nd question: 关于第二个问题:
The documentation on actions is picked up from the documentation file that gets generated when you compile your project. 有关操作的文档是从编译项目时生成的文档文件中获取的。 You can enable it by doing: Project properties | 您可以通过执行以下操作来启用它:项目属性| Build | 建立| Output | 输出| check the 'Xml Documentation File' 检查'Xml文档文件'

Now uncomment the following line in the file 'Areas\\HelpPage\\App_Start\\HelpPageConfig.cs' and set the appropriate path to the documentation file location 现在取消注释文件'Areas \\ HelpPage \\ App_Start \\ HelpPageConfig.cs'中的以下行,并设置文档文件位置的相应路径

//// Uncomment the following to use the documentation from XML documentation
//config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM