question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot host CoreWcf in IIS under ASP.NET Core 3.1

See original GitHub issue

I cannot find a way of hosting a CoreWcf HTTP SOAP service in IIS or IISExpress on versions of ASP.NET Core later than 2.1. Please close the bug if support for IIS on later dot net versions is already planned, thanks.

Repo Steps

In Visual Studio:

  • Create a new ‘ASP.NET Core Web Application’
  • ‘ASP.NET Core 3.1’
  • Select the ‘Empty’ option
  • Add the CoreWcf Nuget packages
  • Add services.AddServiceModelServices(); in ConfigureServices

Error raised

The exception ‘Application is running inside IIS process but is not configured to use IIS serve’ is raised running the code:

System.InvalidOperationException
  HResult=0x80131509
  Message=Application is running inside IIS process but is not configured to use IIS server.
  Source=Microsoft.AspNetCore.Server.IIS
  StackTrace:
   at Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.GenericWebHostService.<StartAsync>d__31.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>d__9.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.<RunAsync>d__4.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.<RunAsync>d__4.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
   at IisCoreWcfTest.Program.Main(String[] args) in C:\Users\jallderidge\source\repos\CoreWcf_IisHostBugReport\IisCoreWcfTest\Program.cs:line 11

  This exception was originally thrown at this call stack:
    Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.Configure.AnonymousMethod__0(Microsoft.AspNetCore.Builder.IApplicationBuilder)

Microsoft.AspNetCore.HostFilteringStartupFilter.Configure.AnonymousMethod__0(Microsoft.AspNetCore.Builder.IApplicationBuilder)
    Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(System.Threading.CancellationToken)
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
    System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
    Microsoft.Extensions.Hosting.Internal.Host.StartAsync(System.Threading.CancellationToken)
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)

Example Code

    public class Program
    {
        public static void Main(string[] args) => CreateHostBuilder(args).Build().Run();

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });
    }

    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            // adding this line will prevent startup in IIS express
            services.AddServiceModelServices();
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
        }
    }

An example solution is at https://github.com/allderidge/CoreWcf_IisHostBugReport

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:20 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
allderidgecommented, May 14, 2021

F.Y.I. after testing with IIS there is an measure you must take in order to get CoreWcf working with Asp.Net Controllers, this is to invoke UseRouting() before UseServiceModel() on the IApplicationBuilder. If you don’t do this then all routed requests for Controllers result in a 404. Note that I’ve only tested this with asp.netcore 5.0 .

E,g,:

public void Configure(IApplicationBuilder app)
{
    app.UseRouting();
    app.UseServiceModel(builder =>
    {
        builder
            .AddService<EchoService>()
            .AddServiceEndpoint<EchoService, IEchoService>(new BasicHttpBinding(), "/basichttp");
    });
    app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllers();
    });
}

In testing this isn’t the case with Kestral or IISExpress but these typically have an empty root address which I’m guessing makes the difference. I.e. app.UseServiceModel somehow causes routing to fail for the url http://localhost/IisCoreWcfTest/api/Test but succeed for http://localhost:5000/api/Test.

I’ve also had to the following for later versions of asp.net to prevent the 'Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true' exception being thrown:

services.Configure<IISServerOptions>(options => // and or the same call with KestrelServerOptions
{
    options.AllowSynchronousIO = true;
});

The exception is coming from HttpRequestContext.cs line 429, which has a the comment '// TODO: Look into useing PipeReader with look-ahead' above it indicating its a known issue.

1reaction
mconnewcommented, Sep 9, 2021

I believe this scenario is working now. If that’s not the case, please reopen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot host CoreWcf in IIS under ASP.NET Core 5.0
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...
Read more >
Issues with Hosting an ASP.NET Core Web Application on IIS
NET Core web application for my WorstBrands website and I'm facing some difficulties in hosting it on IIS (Internet Information Services).
Read more >
IIS hosting of CoreWCF #321
I have one project with original WCF running under IIS where I was using port 443 for my REST ... So my IIS...
Read more >
ASP.NET Core IIS InProcess Hosting Issue in .NET Core 3.1
I ran into a nasty issue yesterday related to hosting an ASP.NET Core 3.1 server application in IIS using the default InProcess hosting....
Read more >
Hosting An ASP.NET Core Web Application In IIS
One issue we have is that for IIS to understand how to talk to .NET Core, it needs a web.config file. Now if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found