webapi help具体配置这里不做太多介绍。一般情况下项目都会分层,webapi help 官方给出的实例是在同一个项目下。
如何支持多个项目呢?
1.在HelpPage下增加 MultiXmlDocumentationProvider.cs文件
1 public class MultiXmlDocumentationProvider : IDocumentationProvider, IModelDocumentationProvider 2 { 3 /********* 4 ** Properties 5 *********/ 6 /// <summary>The internal documentation providers for specific files.</summary> 7 private readonly XmlDocumentationProvider[] Providers; 8 9 10 /********* 11 ** Public methods 12 *********/ 13 /// <summary>Construct an instance.</summary> 14 /// <param name="paths">The physical paths to the XML documents.</param> 15 public MultiXmlDocumentationProvider(params string[] paths) 16 { 17 this.Providers = paths.Select(p => new XmlDocumentationProvider(p)).ToArray(); 18 } 19 20 /// <summary>Gets the documentation for a subject.</summary> 21 /// <param name="subject">The subject to document.</param> 22 public string GetDocumentation(MemberInfo subject) 23 { 24 return this.GetFirstMatch(p => p.GetDocumentation(subject)); 25 } 26 27 /// <summary>Gets the documentation for a subject.</summary> 28 /// <param name="subject">The subject to document.</param> 29 public string GetDocumentation(Type subject) 30 { 31 return this.GetFirstMatch(p => p.GetDocumentation(subject)); 32 } 33 34 /// <summary>Gets the documentation for a subject.</summary> 35 /// <param name="subject">The subject to document.</param> 36 public string GetDocumentation(HttpControllerDescriptor subject) 37 { 38 return this.GetFirstMatch(p => p.GetDocumentation(subject)); 39 } 40 41 /// <summary>Gets the documentation for a subject.</summary> 42 /// <param name="subject">The subject to document.</param> 43 public string GetDocumentation(HttpActionDescriptor subject) 44 { 45 return this.GetFirstMatch(p => p.GetDocumentation(subject)); 46 } 47 48 /// <summary>Gets the documentation for a subject.</summary> 49 /// <param name="subject">The subject to document.</param> 50 public string GetDocumentation(HttpParameterDescriptor subject) 51 { 52 return this.GetFirstMatch(p => p.GetDocumentation(subject)); 53 } 54 55 /// <summary>Gets the documentation for a subject.</summary> 56 /// <param name="subject">The subject to document.</param> 57 public string GetResponseDocumentation(HttpActionDescriptor subject) 58 { 59 return this.GetFirstMatch(p => p.GetDocumentation(subject)); 60 } 61 62 63 /********* 64 ** Private methods 65 *********/ 66 /// <summary>Get the first valid result from the collection of XML documentation providers.</summary> 67 /// <param name="expr">The method to invoke.</param> 68 private string GetFirstMatch(Func<XmlDocumentationProvider, string> expr) 69 { 70 return this.Providers 71 .Select(expr) 72 .FirstOrDefault(p => !String.IsNullOrWhiteSpace(p)); 73 } 74 }
2.修改/HelpPage/App_Start/HelpPageConfig.cs,原先的不用使用。
config.SetDocumentationProvider(new MultiXmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/Areas/HelpPage/Model.XML"), HttpContext.Current.Server.MapPath("~/Areas/HelpPage/WebApiHelp.XML")));