Q1:您是否看过“Areas\HelpPage\App_Start\HelpPageConfig.cs”文件。您应该看到一堆注释掉的示例,您可以如何定义自己的示例。
例子:
public static class HelpPageConfig
{
public static void Register(HttpConfiguration config)
{
//// Uncomment the following to use the documentation from XML documentation file.
//config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));
//// Uncomment the following to use "sample string" as the sample for all actions that have string as the body parameter or return type.
//// Also, the string arrays will be used for IEnumerable<string>. The sample objects will be serialized into different media type
//// formats by the available formatters.
//config.SetSampleObjects(new Dictionary<Type, object>
//{
// {typeof(string), "sample string"},
// {typeof(IEnumerable<string>), new string[]{"sample 1", "sample 2"}}
//});
Q2:您看到“application/x-www-form-urlencoded”媒体类型的错误,因为我们用于它的格式化程序只能反序列化或读取数据而不能写入。这里的错误是表明它只能写样本,但如果你实际上是在这种媒体类型中发送数据,它可以被正确地反序列化。您可以为此媒体类型提供显式示例,而不是隐藏此部分。HelpPageConfig.cs 有这方面的例子:
//// Uncomment the following to use "[0]=foo&[1]=bar" directly as the sample for all actions that support form URL encoded format
//// and have IEnumerable<string> as the body parameter or return type.
//config.SetSampleForType("[0]=foo&[1]=bar", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(IEnumerable<string>));
Q3:关于动作参数的文档,你总是可以使用常规注释(摘要,参数等)并生成文档文件并指向它,如下所示:
//// Uncomment the following to use the documentation from XML documentation file.
//config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));
我们目前不支持从数据注释生成文档,我们目前在跟踪它时遇到问题:http: //aspnetwebstack.codeplex.com/workitem/877