CoreWCF: Cannot host CoreWcf in IIS under ASP.NET Core 3.1
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
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 20 (8 by maintainers)
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,:
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: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.I believe this scenario is working now. If that’s not the case, please reopen.