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


C# HttpSelfHostServer.OpenAsync方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            // Set up server configuration 
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration("http://localhost:8080");

            //Route Catches the GET PUT DELETE typical REST based interactions (add more if needed)
            config.Routes.MapHttpRoute("API Default", "api/{controller}/{id}",
                new { id = RouteParameter.Optional },
                new { httpMethod = new HttpMethodConstraint(HttpMethod.Get, HttpMethod.Put, HttpMethod.Delete) });

            //This allows POSTs to the RPC Style methods http://api/controller/action
            config.Routes.MapHttpRoute("API RPC Style", "api/{controller}/{action}",
                new { httpMethod = new HttpMethodConstraint(HttpMethod.Post) });

            //Finally this allows POST to typeical REST post address http://api/controller/
            config.Routes.MapHttpRoute("API Default 2", "api/{controller}/{action}",
                new { action = "Post" },
                new { httpMethod = new HttpMethodConstraint(HttpMethod.Post) });
            
            using (HttpSelfHostServer server = new HttpSelfHostServer(config))
            {
                server.OpenAsync().Wait();
                Console.WriteLine("Press Enter to quit.");
                Console.ReadLine();
            }
        }
开发者ID:flespinoza,项目名称:StackOverflow,代码行数:26,代码来源:Program.cs

示例2: Start

 public void Start()
 {
     Log.Info("Starting");
     Server = new HttpSelfHostServer(Config);
     Server.OpenAsync().Wait();
     Log.Info("Started");
 }
开发者ID:Zhevranacci,项目名称:OCTGN,代码行数:7,代码来源:ApiManager.cs

示例3: Main

        static void Main(string[] args)
        {
            Assembly.Load("WebApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
            HttpSelfHostConfiguration configuration = new HttpSelfHostConfiguration("http://localhost/selfhost/tyz");//指定基地址
            try
            {
                using (HttpSelfHostServer httpServer = new HttpSelfHostServer(configuration))
                {
                    httpServer.Configuration.Routes.MapHttpRoute(
                     name: "DefaultApi",
                     routeTemplate: "api/{controller}/{id}",
                     defaults: new { id = RouteParameter.Optional });

                    httpServer.OpenAsync().Wait();
                    Console.Read();
                }
            }
            catch (Exception e)
            {
            }

            ////web API的SelfHost寄宿方式通过HttpSelfHostServer来完成
            //using (HttpSelfHostServer httpServer = new HttpSelfHostServer(configuration))
            //{
            //    httpServer.Configuration.Routes.MapHttpRoute(
            //     name: "DefaultApi",
            //     routeTemplate: "api/{controller}/{id}",
            //     defaults: new { id = RouteParameter.Optional });

            //    httpServer.OpenAsync();//开启后,服务器开始监听来自网络的调用请求
            //    Console.Read();
            //}
        }
开发者ID:PaulineTang,项目名称:GitTest,代码行数:33,代码来源:Program.cs

示例4: Given_command_server_runnig

        public void Given_command_server_runnig()
        {
            var config = ZazServer.ConfigureAsSelfHosted(URL);

            _host = new HttpSelfHostServer(config);
            _host.OpenAsync().Wait();
        }
开发者ID:JustApplications,项目名称:zaz,代码行数:7,代码来源:When_connecting_to_server.cs

示例5: Main

        static void Main(string[] args)
        {
            Configuration cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var selfConfig = cfg.GetSection("SeifConfiguration") as SeifConfiguration;

            //var servConfig = new ProviderConfiguration();
            //servConfig.ApiDomain = "api.aaa.com";
            //servConfig.ApiIpAddress = "172.16.1.121";
            //servConfig.SerializeMode = "ssjson";
            //servConfig.Protocol = "Http";
            //servConfig.AddtionalFields.Add(AttrKeys.ApiGetEntrance, "api/get");
            //servConfig.AddtionalFields.Add(AttrKeys.ApiPostEntrance, "api/post");

            //var clientConfig = new ConsumerConfiguration();

            //var registryProvider = new RedisRegistryProvider();
            //var registry = new GenericRegistry(registryProvider, registryProvider);
            //var typeBuilder = new AutofacTypeBuilder();
            ////SeifApplication.Initialize(registry, servConfig, clientConfig, typeBuilder, new ISerializer[]{new ServiceStackJsonSerializer()});

            SeifApplication.Initialize(selfConfig);
            SeifApplication.ExposeService<IDemoService, DemoService>();
            //SeifApplication.ReferenceService<IEchoService>(new ProxyOptions(), new IInvokeFilter[0]);

            SeifApplication.AppEnv.TypeBuilder.Build();

            var config = new HttpSelfHostConfiguration("http://localhost:3333");
            config.Filters.Add(new ExceptionFilter());
            config.Routes.MapHttpRoute("default", "api/{controller}/{action}/{id}", new { id = RouteParameter.Optional });
            var server = new HttpSelfHostServer(config);
            server.OpenAsync().Wait();
            Console.WriteLine("Server is opened");
            Console.Read();
        }
开发者ID:tukzer,项目名称:Seif,代码行数:34,代码来源:Program.cs

示例6: SendJsonGetJson

        public static JObject SendJsonGetJson(HttpMethod method, string routeTemp, string uri, string json)
        {
            JObject result;

            HttpSelfHostConfiguration config
                = new HttpSelfHostConfiguration("http://localhost/");
            config.Routes.MapHttpRoute(
                name: "Default",
                routeTemplate: routeTemp
                );

            using (HttpSelfHostServer server = new HttpSelfHostServer(config))
            using (HttpClient client = getJsonClient())
            {
                server.OpenAsync().Wait();
                using (HttpRequestMessage request =
                    getJsonRequest(method, uri, json))
                using (HttpResponseMessage response = client.SendAsync(request).Result)
                {
                    string responseJson = response.Content.ReadAsStringAsync().Result;
                    result = JObject.Parse(responseJson);
                }
                server.CloseAsync().Wait();
            }
            return result;
        }
开发者ID:pacholik,项目名称:driving_scools_server,代码行数:26,代码来源:AssertHelper.cs

示例7: Start

        public void Start()
        {
            selfHostServer = new HttpSelfHostServer(httpSelfHostConfiguration);
            selfHostServer.OpenAsync();

            Logger.Info("Started management app host");
        }
开发者ID:jonnii,项目名称:statr,代码行数:7,代码来源:ManagementBootstrapper.cs

示例8: Main

        static void Main(string[] args)
        {
            var config = new HttpSelfHostConfiguration("http://localhost:8999");
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
            // using asp.net like hosting
            // HttpSelfHostServer is using a different constructor compared to the previous project (SelfHost1)
            var server = new HttpSelfHostServer(config);
            var task = server.OpenAsync();
            task.Wait();
            Console.WriteLine("Server is up and running");
            Console.WriteLine("Hit enter to call server with client");
            Console.ReadLine();

            // HttpSelfHostServer, derives from HttpMessageHandler => multiple level of inheritance
            var client = new HttpClient(server);
            client.GetAsync("http://localhost:8999/api/my").ContinueWith(t =>
            {
                var result = t.Result;
                result.Content.ReadAsStringAsync()
                    .ContinueWith(rt =>
                    {
                        Console.WriteLine("client got response" + rt.Result);
                    });
            });

            Console.ReadLine();
        }
开发者ID:randelramirez,项目名称:IntroductionWebApi,代码行数:31,代码来源:Program.cs

示例9: WebApiTest

		public WebApiTest()
		{
			IOExtensions.DeleteDirectory("Test");
			NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(19079);
			Task.Factory.StartNew(() => // initialize in MTA thread
				                      {
					                      config = new HttpSelfHostConfiguration(Url)
						                               {
							                               MaxReceivedMessageSize = Int64.MaxValue,
							                               TransferMode = TransferMode.Streamed
						                               };
					                      var configuration = new InMemoryConfiguration();
					                      configuration.Initialize();
					                      configuration.DataDirectory = "~/Test";
					                      ravenFileSystem = new RavenFileSystem(configuration);
					                      ravenFileSystem.Start(config);
				                      })
			    .Wait();

			server = new HttpSelfHostServer(config);
			server.OpenAsync().Wait();

			WebClient = new WebClient
				            {
					            BaseAddress = Url
				            };
		}
开发者ID:hibernating-rhinos,项目名称:RavenFS,代码行数:27,代码来源:WebApiTest.cs

示例10: Main

 static void Main(string[] args)
 {
     HttpSelfHostServer server = null;
     try {
         // Set up server configuration
         HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(BaseAddress);
         config.Routes.MapHttpRoute(
             name: "DefaultApi",
             routeTemplate: "api/{controller}/{id}",
             defaults: new { id = RouteParameter.Optional }
         );
         // Create server
         server = new HttpSelfHostServer(config);
         // Start listening
         server.OpenAsync().Wait();
         Console.WriteLine("Listening on " + BaseAddress);
         Console.ReadLine();
     }
     catch (Exception e) {
         Console.WriteLine("Could not start server: {0}", e.GetBaseException().Message);
         Console.WriteLine("Hit ENTER to exit...");
         Console.ReadLine();
     }
     finally {
         if (server != null) {
             // Stop listening
             server.CloseAsync().Wait();
         }
     }
 }
开发者ID:djsolid,项目名称:win8-ws-samples,代码行数:30,代码来源:Program.cs

示例11: SetUp

        public void SetUp()
        {
            var config = new HttpSelfHostConfiguration(URL);

            ZazServer.Configure(config, Prefix1, new ServerConfiguration
            {
                Registry = new FooCommandRegistry(),
                Broker = new DelegatingCommandBroker((o, context) =>
                {
                    _api1Command = (FooCommand)o;
                    return Task.Factory.StartNew(() => { });
                }),
            });
            ZazServer.Configure(config, Prefix2, new ServerConfiguration
            {
                Registry = new FooCommandRegistry(),
                Broker = new DelegatingCommandBroker((o, context) =>
                {
                    _api2Command = (FooCommand)o;
                    return Task.Factory.StartNew(() => { });
                }),
            });

            _host = new HttpSelfHostServer(config);
            _host.OpenAsync().Wait();
        }
开发者ID:JustApplications,项目名称:zaz,代码行数:26,代码来源:When_configuring_multiple_endpoints_within_1_webhost.cs

示例12: Main

        private static void Main(string[] args) {
            string prefix = "http://localhost:8080";
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(prefix);
            config.Routes.MapHttpRoute("Default", "{controller}/{action}");

            // Append our custom valueprovider to the list of value providers.
            config.Services.Add(typeof (ValueProviderFactory), new HeaderValueProviderFactory());

            HttpSelfHostServer server = new HttpSelfHostServer(config);
            server.OpenAsync().Wait();

            try {
                // HttpClient will make the call, but won't set the headers for you. 
                HttpClient client = new HttpClient();
                var response = client.GetAsync(prefix + "/ValueProviderTest/GetStuff?id=20").Result;

                // Browsers will set the headers. 
                // Loop. You can hit the request via: http://localhost:8080/Test2/GetStuff?id=40
                while (true) {
                    Thread.Sleep(1000);
                    Console.Write(".");
                }
            }
            finally {
                server.CloseAsync().Wait();
            }
        }
开发者ID:tugberkugurlu,项目名称:ProWebAPI.Samples,代码行数:27,代码来源:Program.cs

示例13: Setup

 public void Setup()
 {
     BaseAddress = GetBaseAddress();
     HttpConfiguration = GetHttpConfiguration();
     Server = new HttpSelfHostServer(HttpConfiguration);
     Server.OpenAsync().Wait();
 }
开发者ID:pstephens,项目名称:fbclient,代码行数:7,代码来源:SetupFixture.cs

示例14: Main

        static void Main(string[] args)
        {
            HttpSelfHostServer server = null;
            try
            {
                HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(baseAddress);
                config.HostNameComparisonMode = HostNameComparisonMode.Exact;

                // Register default route
                config.Routes.MapHttpRoute(
                    name: "DefaultApi",
                    routeTemplate: "api/{controller}"
                );

                server = new HttpSelfHostServer(config);
                server.OpenAsync().Wait();
                Console.WriteLine("Listening on " + baseAddress);
                Console.WriteLine("Hit ENTER to exit...");
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not start server: {0}", e.GetBaseException().Message);
                Console.WriteLine("Hit ENTER to exit...");
                Console.ReadLine();
            }
            finally
            {
                if (server != null)
                {
                    server.CloseAsync().Wait();
                }
            }
        }
开发者ID:ericziko,项目名称:edge,代码行数:34,代码来源:Program.cs

示例15: Main

        static void Main(string[] args)
        {
            // classic
            var config = new HttpSelfHostConfiguration("http://localhost:18081");

            // HTTPS
            //var config = new HttpsSelfHostConfiguration("http://localhost:18081");

            // NTLM
            //var config = new NtlmHttpSelfHostConfiguration("http://localhost:18081");


            // BASIC AUTHENTICATION
            //var config = new BasicAuthenticationSelfHostConfiguration("http://localhost:18081",
            //    (un, pwd) => un == "johndoe" && pwd == "123456");



            config.Routes.MapHttpRoute(
                "API Default", "api/{controller}/{id}",
                new { id = RouteParameter.Optional });

            using (var server = new HttpSelfHostServer(config))
            {
                server.OpenAsync().Wait();
                Console.WriteLine("Press Enter to quit.");
                Console.ReadLine();
            }
        }
开发者ID:tugberkugurlu,项目名称:ProWebAPI.Samples,代码行数:29,代码来源:Program.cs


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