Cannot host CoreWcf in IIS under ASP.NET Core 5.0

Viewed 1016

I try to do the migration of my WCF web service from .Net Framework 4.7.1 to .Net5.0. I use the nugget CoreWcf and I'm trying to run it on IIS.

Reading this issue* I'm not sure if we can or not use IIS hosting with nuget WcfCore 0.1.0.

*"Cannot host CoreWcf in IIS under ASP.NET Core 3.1 : https://github.com/CoreWCF/CoreWCF/issues/313"

Here what I observe when running my app

An error occurred while starting the application. InvalidOperationException: Application is running inside IIS process but is not configured to use IIS server. Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter+<>c__DisplayClass2_0.b__0(IApplicationBuilder app)

Program.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();
            });
        }
    }

My csproj

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

LaucheSettings:

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

When I launch as "Project" it works well but I would like to host it on IIS.

I tried the workaround from https://www.gitmemory.com/issue/CoreWCF/CoreWCF/313/782387998

It doesn't work as well because the application is launched but all requests return an empty response 202 Accepted.

At the moment is it possible to host my WCF service on IIS with .Net5 ?

Updated

Thanks for your feedback !

Finally I'm hosting my WCF services as Windows Service following this documentation :

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

and

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();

Hope in the future we'll move our services to gRPC.

1 Answers
Related