本文整理汇总了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();
}
}
示例2: Start
public void Start()
{
Log.Info("Starting");
Server = new HttpSelfHostServer(Config);
Server.OpenAsync().Wait();
Log.Info("Started");
}
示例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();
//}
}
示例4: Given_command_server_runnig
public void Given_command_server_runnig()
{
var config = ZazServer.ConfigureAsSelfHosted(URL);
_host = new HttpSelfHostServer(config);
_host.OpenAsync().Wait();
}
示例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();
}
示例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;
}
示例7: Start
public void Start()
{
selfHostServer = new HttpSelfHostServer(httpSelfHostConfiguration);
selfHostServer.OpenAsync();
Logger.Info("Started management app host");
}
示例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();
}
示例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
};
}
示例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();
}
}
}
示例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();
}
}
示例13: Setup
public void Setup()
{
BaseAddress = GetBaseAddress();
HttpConfiguration = GetHttpConfiguration();
Server = new HttpSelfHostServer(HttpConfiguration);
Server.OpenAsync().Wait();
}
示例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();
}
}
}
示例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();
}
}