无法在 ASP.NET Core 5.0 下的 IIS 中托管 CoreWcf

问题描述

我尝试将我的 WCF Web 服务从 .Net Framework 4.7.1 迁移到 .Net5.0。 我使用 nugget CoreWcf 并尝试在 IIS 上运行它。

阅读此问题*我不确定我们是否可以将 IIS 托管与 nuget WcfCore 0.1.0 一起使用。

*"无法在 ASP.NET Core 3.1 下的 IIS 中托管 CoreWcf: https://github.com/CoreWCF/CoreWCF/issues/313"

这是我在运行我的应用程序时观察到的

启动应用程序时出错。 InvalidOperationException: 应用程序正在 IIS 进程内运行,但未配置为使用 IIS 服务器。 Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter+c__displayClass2_0.b__0(IApplicationBuilder 应用)

程序.cs

    public class Program
    {
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
            .UseIISIntegration()
            .UseStartup<Startup>()
            ;
    }

Startup.cs

    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddServiceModelServices();
            services.Configure<IISServerOptions>(options => // and or the same call with KestrelServerOptions
            {
                options.AllowSynchronousIO = true;
            });
            services.AddRouting();
            services.AddControllers();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,IWebHostEnvironment env)
        {
            app.UseRouting();
            app.UseServiceModel(builder =>
            {
                builder
                    .AddService<MyService>()
                    .AddServiceEndpoint<MyService,IMyService>(new BasicHttpBinding(),"/service.svc");

            });
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }

我的 csproj

 <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <OutputType>Exe</OutputType>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup>

启动设置:

 "IIS": {
      "commandName": "IIS","launchbrowser": true,"launchUrl": "http://localhost/service.svc","environmentvariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },

当我作为“项目”启动时,它运行良好,但我想将它托管在 IIS 上。

我尝试了 https://www.gitmemory.com/issue/CoreWCF/CoreWCF/313/782387998

中的解决方法

效果不佳,因为应用程序已启动,但所有请求都返回空响应 202 Accepted。

目前是否可以使用 .Net5 在 IIS 上托管我的 WCF 服务?

更新

感谢您的反馈!

最后,我按照此文档将 WCF 服务托管为 Windows 服务:

https://docs.microsoft.com/fr-fr/aspnet/core/host-and-deploy/windows-service?view=aspnetcore-5.0&tabs=visual-studio

https://dotnetcoretutorials.com/2019/12/21/hosting-an-asp-net-core-web-app-as-a-windows-service-in-net-core-3/

  Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();

                }).ConfigureWebHost(config =>
                {
                    config.UseUrls("http://*:5050");

                })
                .UseWindowsService();

希望将来我们将服务迁移到 gRPC。

解决方法

Wcf 在 .net 5 中受到很多限制。如果你想迁移,你可以检查 .net 5 中是否支持你的 wcf 服务的各种功能。

这里有一些参考:Supporting the community with WF and WCF OSS projects

这是netcore中支持的wcf特性,你可以看看:WCF Features in .Net Core 2.0