本文整理汇总了C#中System.Web.Http.HttpConfiguration.SetDocumentationProvider方法的典型用法代码示例。如果您正苦于以下问题:C# HttpConfiguration.SetDocumentationProvider方法的具体用法?C# HttpConfiguration.SetDocumentationProvider怎么用?C# HttpConfiguration.SetDocumentationProvider使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Http.HttpConfiguration
的用法示例。
在下文中一共展示了HttpConfiguration.SetDocumentationProvider方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Register
public static void Register(HttpConfiguration config)
{
config.Formatters.Clear();
config.Formatters.Add(new JsonMediaTypeFormatter());
config.Formatters.Add(new XmlMediaTypeFormatter());
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/Bin/GT.CS6460.BuddyUp.Controllers.XML")));
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/Bin/GT.CS6460.BuddyUp.DomainDto.xml")));
//// 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"}}
//});
// Extend the following to provide factories for types not handled automatically (those lacking parameterless
// constructors) or for which you prefer to use non-default property values. Line below provides a fallback
// since automatic handling will fail and GeneratePageResult handles only a single type.
#if Handle_PageResultOfT
config.GetHelpPageSampleGenerator().SampleObjectFactories.Add(GeneratePageResult);
#endif
// Extend the following to use a preset object directly as the sample for all actions that support a media
// type, regardless of the body parameter or return type. The lines below avoid display of binary content.
// The BsonMediaTypeFormatter (if available) is not used to serialize the TextSample object.
config.SetSampleForMediaType(
new TextSample("Binary JSON content. See http://bsonspec.org for details."),
new MediaTypeHeaderValue("application/bson"));
//// 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>));
//// Uncomment the following to use "1234" directly as the request sample for media type "text/plain" on the controller named "Values"
//// and action named "Put".
//config.SetSampleRequest("1234", new MediaTypeHeaderValue("text/plain"), "Values", "Put");
//// Uncomment the following to use the image on "../images/aspNetHome.png" directly as the response sample for media type "image/png"
//// on the controller named "Values" and action named "Get" with parameter "id".
//config.SetSampleResponse(new ImageSample("../images/aspNetHome.png"), new MediaTypeHeaderValue("image/png"), "Values", "Get", "id");
//// Uncomment the following to correct the sample request when the action expects an HttpRequestMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Get" were having string as the body parameter.
//config.SetActualRequestType(typeof(string), "Values", "Get");
//// Uncomment the following to correct the sample response when the action returns an HttpResponseMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Post" were returning a string.
//config.SetActualResponseType(typeof(string), "Values", "Post");
}
示例2: Register
public static void Register(HttpConfiguration config, bool registerAreas = true)
{
if (registerAreas)
{
//registers areas - help page mvc app
AreaRegistration.RegisterAllAreas();
//help page documentation
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));
}
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "TransactionsApi",
routeTemplate: "api/{controller}/{id}",
defaults: new
{
controller = "Transactions",
id = RouteParameter.Optional
}
);
//replacing dependecy resolver to enable ioc
config.DependencyResolver = new NinjectResolver(NinjectBootstrap.CreateKernel());
}
示例3: Register
public static void Register(HttpConfiguration config)
{
// Web API routes
config.MapHttpAttributeRoutes();
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/FGV.TechnicalEvaluation.WebApi.xml")));
}
示例4: Register
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/teaCRM.Web.Api.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"}}
//});
//// 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>));
//// Uncomment the following to use "1234" directly as the request sample for media type "text/plain" on the controller named "Values"
//// and action named "Put".
//config.SetSampleRequest("1234", new MediaTypeHeaderValue("text/plain"), "Values", "Put");
//// Uncomment the following to use the image on "../images/aspNetHome.png" directly as the response sample for media type "image/png"
//// on the controller named "Values" and action named "Get" with parameter "id".
//config.SetSampleResponse(new ImageSample("../images/aspNetHome.png"), new MediaTypeHeaderValue("image/png"), "Values", "Get", "id");
//// Uncomment the following to correct the sample request when the action expects an HttpRequestMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Get" were having string as the body parameter.
//config.SetActualRequestType(typeof(string), "Values", "Get");
//// Uncomment the following to correct the sample response when the action returns an HttpResponseMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Post" were returning a string.
//config.SetActualResponseType(typeof(string), "Values", "Post");
}
示例5: Register
public static void Register(HttpConfiguration config)
{
//Auth filter - See configuration in web.config
config.Filters.Add(new SeranetAuthAttribute());
// set webapi JSON formatter
config.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
var json = config.Formatters.JsonFormatter;
json.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
json.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
//enable cross domain requests
var corsAttr = new EnableCorsAttribute("*", "*", "*");
corsAttr.SupportsCredentials = true;
config.EnableCors(corsAttr);
// Web API routes
config.MapHttpAttributeRoutes();
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/bin/Seranet.Api.xml")));
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
示例6: Register
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
//http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api
config.EnableCors();
config.SetDocumentationProvider(new XmlDocumentationProvider(
HttpContext.Current.Server.MapPath("~/App_Data/WebApi2.XML")));
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
//http://stackoverflow.com/a/9521363
FilterConfig.RegisterWebApiFilters(GlobalConfiguration.Configuration.Filters);
//http://www.asp.net/web-api/overview/testing-and-debugging/tracing-in-aspnet-web-api
//IsVerbose: If false, each trace contains minimal information. If true, traces include more information.
//MinimumLevel: Sets the minimum trace level. Trace levels, in order, are Debug, Info, Warn, Error, and Fatal.
SystemDiagnosticsTraceWriter traceWriter = config.EnableSystemDiagnosticsTracing();
traceWriter.IsVerbose = false;
traceWriter.MinimumLevel = TraceLevel.Info;
config.EnableSystemDiagnosticsTracing();
config.Services.Replace(typeof(ITraceWriter), new LoggingTracer());
}
示例7: Register
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), "{'status':'Succeeded','result':[{'localUrl':'http://localhost/ImagesDownloader/Images/ximnobo2.vqo/c9aef841-7cd2-47e3-be25-436c091101c5.gif','remoteUrl':'https://cdn0.vox-cdn.com/images/verge/default-avatar.v9899025.gif','width':0,'height':0,'size':2926,'contentType':'image/gif'}]}"},
{typeof(IEnumerable<string>), new string[]{"sample 1", "sample 2"}}
});
// Extend the following to provide factories for types not handled automatically (those lacking parameterless
// constructors) or for which you prefer to use non-default property values. Line below provides a fallback
// since automatic handling will fail and GeneratePageResult handles only a single type.
#if Handle_PageResultOfT
config.GetHelpPageSampleGenerator().SampleObjectFactories.Add(GeneratePageResult);
#endif
// Extend the following to use a preset object directly as the sample for all actions that support a media
// type, regardless of the body parameter or return type. The lines below avoid display of binary content.
// The BsonMediaTypeFormatter (if available) is not used to serialize the TextSample object.
/*config.SetSampleForMediaType(
new TextSample("Binary JSON content. See http://bsonspec.org for details."),
new MediaTypeHeaderValue("application/bson"));*/
//// 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>));
//// Uncomment the following to use "1234" directly as the request sample for media type "text/plain" on the controller named "Values"
//// and action named "Put".
//config.SetSampleRequest("1234", new MediaTypeHeaderValue("text/plain"), "Jobs", "Get");
config.SetSampleRequest("{'value': 'http://www.theverge.com'}}", new MediaTypeHeaderValue("application/json"), "Jobs", "Post");
//// Uncomment the following to use "1234" directly as the request sample for media type "text/plain" on the controller named "Values"
//// and action named "Put".
//config.SetSampleRequest("1234", new MediaTypeHeaderValue("text/plain"), "Values", "Put");
//// Uncomment the following to use the image on "../images/aspNetHome.png" directly as the response sample for media type "image/png"
//// on the controller named "Values" and action named "Get" with parameter "id".
//config.SetSampleResponse(new ImageSample("../images/aspNetHome.png"), new MediaTypeHeaderValue("image/png"), "Values", "Get", "id");
//// Uncomment the following to correct the sample request when the action expects an HttpRequestMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Get" were having string as the body parameter.
//config.SetActualRequestType(typeof(string), "Jobs", "Get");
//// Uncomment the following to correct the sample response when the action returns an HttpResponseMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Post" were returning a string.
config.SetActualResponseType(typeof(string), "Jobs", "GetById");
}
示例8: Register
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.SetDocumentationProvider(new XmlDocumentationProvider(
HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
示例9: Register
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.SetDocumentationProvider(new XmlDocumentationProvider(
HttpContext.Current.Server.MapPath("App_Data/CertificatesBackend.XML")));
config.MessageHandlers.Add(new LogRequestAndResponseHandler());
}
示例10: Register
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/ContactManager.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(Contact), SampleData.Contacts[0]},
{typeof(IEnumerable<Contact>), SampleData.Contacts}
});
//// 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(
"Name=Daniel Roth&Address=One+Microsoft+Way&City=Redmond&State=WA&Zip=98011&Email=&Twitter=",
new MediaTypeHeaderValue("application/x-www-form-urlencoded"),
typeof(Contact));
config.SetSampleForType(
new ImageSample(HttpContext.Current.Server.MapPath("~/Images/Image1.png")),
new MediaTypeHeaderValue("image/png"),
typeof(Contact));
//// Uncomment the following to use "1234" directly as the request sample for media type "text/plain" on the controller named "Values"
//// and action named "Put".
//config.SetSampleRequest("1234", new MediaTypeHeaderValue("text/plain"), "Values", "Put");
//// Uncomment the following to use the image on "../images/aspNetHome.png" directly as the response sample for media type "image/png"
//// on the controller named "Values" and action named "Get" with parameter "id".
//config.SetSampleResponse(new ImageSample("../images/aspNetHome.png"), new MediaTypeHeaderValue("image/png"), "Values", "Get", "id");
//// Uncomment the following to correct the sample request when the action expects an HttpRequestMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Get" were having string as the body parameter.
//config.SetActualRequestType(typeof(string), "Values", "Get");
//// Uncomment the following to correct the sample response when the action returns an HttpResponseMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Post" were returning a string.
config.SetActualResponseType(typeof(Contact), "Contacts", "Post");
}
示例11: Register
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
//http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api
config.EnableCors();
config.SetDocumentationProvider(new XmlDocumentationProvider(
HttpContext.Current.Server.MapPath("~/App_Data/WebApi2.XML")));
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
}
示例12: UseWebApiHelpPage
public static void UseWebApiHelpPage(this IAppBuilder app, HttpConfiguration httpConfiguration, string helpRoute=null, string viewsPhysicalPath=null, string xmlDocumentationPhysicalPath=null, dynamic viewBag=null)
{
const string defaultRoute = "help";
var executingAssemblyPath = GetBinPath();
var executingAssemblyName = Assembly.GetCallingAssembly().GetName().Name;
helpRoute = helpRoute ?? defaultRoute;
viewsPhysicalPath = viewsPhysicalPath ?? executingAssemblyPath.Replace("file:\\", string.Empty) + "\\Help\\DalSoft.WebApi.HelpPage.Views";
xmlDocumentationPhysicalPath = xmlDocumentationPhysicalPath ?? executingAssemblyPath + "//" + executingAssemblyName + ".xml";
IDictionary<string, object> viewBagDictionary = DynamicToDictionary(viewBag);
if (helpRoute.StartsWith("/"))
helpRoute = helpRoute.Substring(1, helpRoute.Length - 1);
viewBagDictionary.Add("HelpRoute", helpRoute);
// Configure help page
httpConfiguration.SetDocumentationProvider(new XmlDocumentationProvider(xmlDocumentationPhysicalPath));
app.Map("/" + helpRoute, appBuilder => appBuilder.Use<HelpPageMiddleware>(httpConfiguration, helpRoute, viewsPhysicalPath, viewBagDictionary));
}
示例13: Register
public static void Register(HttpConfiguration config) {
// Web API configuration and services
config.SetDocumentationProvider(
new XmlDocumentationProvider(
HostingEnvironment.MapPath("~/bin/" + typeof (WebApiConfig).Assembly.GetName().Name + ".xml")));
var dependencyContainer = new TinyIoCContainer();
// API versioning
config.Services.Replace(typeof (IHttpControllerSelector), new VersionedApiControllerSelector(config));
config.Services.Replace(typeof(IApiExplorer), new VersionedApiExplorer(config));
config.DependencyResolver = new DependencyResolver(dependencyContainer);
dependencyContainer.Register((c, np) => new DefaultControllerIdentificationDetector(config));
dependencyContainer.Register((c, np) => new DefaultRequestControllerIdentificationDetector(config));
ApiVersioning.Configure(config)
.ConfigureRequestVersionDetector<DefaultRouteKeyVersionDetector>();
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute("DefaultApi", "api/v{version}/{controller}/{id}", new {id = RouteParameter.Optional});
}
示例14: CreateModelDescription_ComplexType_WithDocumentation
public void CreateModelDescription_ComplexType_WithDocumentation(Type type, Dictionary<string, string> documentationMapping)
{
HttpConfiguration config = new HttpConfiguration();
config.SetDocumentationProvider(new XmlDocumentationProvider("WebApiHelpPage.Test.XML"));
ModelDescriptionGenerator modelGenerator = new ModelDescriptionGenerator(config);
ComplexTypeModelDescription complexModel = Assert.IsType<ComplexTypeModelDescription>(modelGenerator.GetOrCreateModelDescription(type));
Assert.NotNull(complexModel);
Assert.Equal(type, complexModel.ModelType);
Assert.Equal(documentationMapping.Count, complexModel.Properties.Count);
foreach (var property in complexModel.Properties)
{
string expectedDocumentation = documentationMapping[property.Name];
Assert.Equal(expectedDocumentation, property.Documentation);
}
}
示例15: SetDocumentationProvider
public void SetDocumentationProvider()
{
HttpConfiguration config = new HttpConfiguration();
Mock<IDocumentationProvider> docProviderMock = new Mock<IDocumentationProvider>();
IDocumentationProvider docProvider = docProviderMock.Object;
config.SetDocumentationProvider(docProvider);
Assert.Same(docProvider, config.Services.GetDocumentationProvider());
}