当前位置: 首页>>代码示例>>C#>>正文


C# HttpConfiguration.SetActualRequestType方法代码示例

本文整理汇总了C#中System.Web.Http.HttpConfiguration.SetActualRequestType方法的典型用法代码示例。如果您正苦于以下问题:C# HttpConfiguration.SetActualRequestType方法的具体用法?C# HttpConfiguration.SetActualRequestType怎么用?C# HttpConfiguration.SetActualRequestType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Http.HttpConfiguration的用法示例。


在下文中一共展示了HttpConfiguration.SetActualRequestType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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), "sample string"},
                    {typeof (IEnumerable<string>), new[] {"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");
        }
开发者ID:jorik041,项目名称:AspWithWASE,代码行数:34,代码来源:HelpPageConfig.cs

示例2: 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")));
            config.SetDocumentationProvider(new MultiXmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml"), HttpContext.Current.Server.MapPath("~/App_Data/WebAPI2PostMan.WebModel.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");
        }
开发者ID:chenkaibin,项目名称:WebAPI2PostMan,代码行数:49,代码来源:HelpPageConfig.cs

示例3: SetActualRequestType_WithParameters

 public void SetActualRequestType_WithParameters()
 {
     HttpConfiguration config = new HttpConfiguration();
     config.SetActualRequestType(typeof(string), "c", "a", "id");
     object sampleGeneratorObj;
     config.Properties.TryGetValue(typeof(HelpPageSampleGenerator), out sampleGeneratorObj);
     HelpPageSampleGenerator sampleGenerator = Assert.IsType<HelpPageSampleGenerator>(sampleGeneratorObj);
     Assert.NotEmpty(sampleGenerator.ActualHttpMessageTypes);
     var actualType = sampleGenerator.ActualHttpMessageTypes.First();
     Assert.Equal("c", actualType.Key.ControllerName);
     Assert.Equal("a", actualType.Key.ActionName);
     Assert.Null(actualType.Key.MediaType);
     Assert.Equal(SampleDirection.Request, actualType.Key.SampleDirection);
     Assert.NotEmpty(actualType.Key.ParameterNames);
     Assert.Equal("id", actualType.Key.ParameterNames.First());
     Assert.Equal(typeof(string), actualType.Value);
 }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:17,代码来源:HelpPageConfigurationExtensionsTest.cs


注:本文中的System.Web.Http.HttpConfiguration.SetActualRequestType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。