简体   繁体   English

在C#中使用Web Api 2作为自助控制台主机

[英]Using Web Api 2 as Self Console Host in C#

I want to build a self Host of a Web Api 2 Webservice. 我想构建一个Web Api 2 Web服务的自托管主机。 I am using the .Net Core 1.0 Framework for my Console App and also for the Web Api 2 Project. 我正在为控制台应用程序和Web Api 2项目使用.Net Core 1.0框架。

Since there was a name change for the packages and Owin is deprecated, I am not able to rebuild the given samples in the official GitHub repository of ASPnet: 由于软件包的名称已更改并且不赞成使用Owin,因此我无法在ASPnet的官方GitHub存储库中重建给定的示例:

https://github.com/aspnet/Hosting/blob/dev/samples/SampleStartups/StartupHelloWorld.cs (I tried with this one) https://github.com/aspnet/Hosting/blob/dev/samples/SampleStartups/StartupHelloWorld.cs (我尝试过使用此方法)

I looked in the project.json file which packages they are using but since I can´t find the AspNetCore.Hosting package only a package named AspNet.Hosting but i isn´t working with both packages. 我查看了他们正在使用哪个程序包的project.json文件,但是由于找不到AspNetCore.Hosting程序包,所以只有一个名为AspNet.Hosting的程序包,但我无法同时使用这两个程序包。

{
  "version": "1.0.0-*",
  "dependencies": {
    "Microsoft.AspNetCore.Hosting": "1.0.0-*",
    "Microsoft.NETCore.Platforms": "1.0.1-*"
},

Resharper says something like : Resharper说类似:

Severity Code Description Project File Line Suppression State Error CS0246 The type or namespace name 'WebHostBuilder' could not be found (are you missing a using directive or an assembly reference?) WebApiConsoleHost.DNX 4.5.1, WebApiConsoleHost.DNX Core 5.0 严重性代码说明项目文件行抑制状态错误CS0246找不到类型或名称空间名称“ WebHostBuilder”(您是否缺少using指令或程序集引用?)WebApiConsoleHost.DNX 4.5.1,WebApiConsoleHost.DNX Core 5.0

Just to be complete, I used the whole Main Function Body of the given sample in the Link: 为了完整起见,我在链接中使用了给定示例的整个Main Function Body:

public static void Main(string[] args)
{
    var host = new WebHostBuilder()
        .UseDefaultConfiguration(args)
        .UseStartup<StartupHelloWorld>()
        .Build();

    host.Run();
}

Do someone know where the WebHostBuilder class is defined ? 有人知道WebHostBuilder类的定义位置吗? Resharper suggests that it is in AspNet.Hosting, but after adding the using it is still not found! Resharper建议它位于AspNet.Hosting中,但添加使用后仍找不到它!

Try to read the latest docs . 尝试阅读最新文档 It is working for me. 它为我工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM