當前位置: 首頁>>代碼示例>>C#>>正文


C# HttpSelfHostConfiguration.Dispose方法代碼示例

本文整理匯總了C#中System.Web.Http.SelfHost.HttpSelfHostConfiguration.Dispose方法的典型用法代碼示例。如果您正苦於以下問題:C# HttpSelfHostConfiguration.Dispose方法的具體用法?C# HttpSelfHostConfiguration.Dispose怎麽用?C# HttpSelfHostConfiguration.Dispose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Web.Http.SelfHost.HttpSelfHostConfiguration的用法示例。


在下文中一共展示了HttpSelfHostConfiguration.Dispose方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ValueController_WithGetMethos_ShouldReturnValidData_NoBaseClass

        public void ValueController_WithGetMethos_ShouldReturnValidData_NoBaseClass()
        {
            HttpSelfHostConfiguration configuration = new HttpSelfHostConfiguration("http://localhost:8080");
            configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
            configuration.Services.Replace(typeof(IAssembliesResolver), new WebApiClassBase.TestAssemblyResolver(typeof(ValuesController)));
            configuration.Routes.MapHttpRoute("Default", "{controller}", new { controller = "Home" });

            HttpSelfHostServer server = new HttpSelfHostServer(configuration);
            try
            {
                server.OpenAsync().Wait();

                var request = new HttpRequestMessage();

                request.RequestUri = new Uri("http://localhost:8080");

                request.Method = HttpMethod.Get;

                var client = new HttpClient(server);
                using (HttpResponseMessage response = client.SendAsync(request).Result)
                {
                    response.Should().Not.Be.Null();
                    response.IsSuccessStatusCode.Should().Be.True();

                    string[] result = response.Content.ReadAsAsync<string[]>().Result;

                    result.Length.Should().Be.EqualTo(4);
                    result[0].Should().Be.EqualTo("http://tostring.it");
                    result[1].Should().Be.EqualTo("http://imperugo.tostring.it");
                    result[2].Should().Be.EqualTo("http://twitter.com/imperugo");
                    result[3].Should().Be.EqualTo("http://www.linkedin.com/in/imperugo");
                }
            }
            finally
            {
                configuration.Dispose();
                server.Dispose();
            }
        }
開發者ID:bmontemer,項目名稱:Spike,代碼行數:39,代碼來源:ValuesControllerWithoutBaseClass.cs


注:本文中的System.Web.Http.SelfHost.HttpSelfHostConfiguration.Dispose方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。