9

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. Below is my example.

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

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

Hierarchy

API--------------------------Description

GET api/Hierarchy-------Gets Hierarchy(s) by guid(s)

POST api/Hierarchy-----No documentation available.

DELETE api/Hierarchy--Deletes Hierarchy(s)

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

/// <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." 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)?

4

1 回答 1

10

关于第一个问题:
List<Guid>即使用 FromUri 装饰也不能像您期望的那样绑定模型。这是一个最近修复的错误,我认为您正在使用以前的版本位,因此可能无法看到这一点。你可以通过改变所有出现的[FromUri]List<Guid> guidwith let's say来理解我的意思string guid。您现在应该可以在帮助页面中看到所有路线。顺便说一句,ApiExplorer 探索每条路线,并且对于每条路线,它会探索该路线中所有可到达的控制器。因此,您将看到的结果可能令人惊讶,但它们是正确的……仅供参考。

关于第二个问题:
有关操作的文档是从您编译项目时生成的文档文件中提取的。您可以通过以下方式启用它:项目属性 | 构建 | 输出 | 检查“XML 文档文件”

现在取消注释文件 '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")));
于 2013-06-07T20:20:20.307 回答