I have created for testing a simple WCF service using the .NET 8 framework.
Endpoints are defined in a wcf.config file (follows). The Program.cs looks like this:
internal class Program
{
static void Main(string[] args)
{
var host = CreateBuilders(args).Build();
host.Run();
}
public static IHostBuilder CreateBuilders(string[] args)
{
return Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseContentRoot(Directory.GetCurrentDirectory());
webBuilder.UseIISIntegration();
webBuilder.UseStartup<Startup>();
});
}
}
The project is using the following two frameworks:
Microsoft.AspNetCore.AppMicrosoft.NETCore.App
The Startup class is basically following many tutorials available on MS site and is:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddServiceModelServices()
.AddServiceModelConfigurationManagerFile("wcf.config");
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
}
app.UseStaticFiles();
app.UseRouting();
}
}
Now the endpoint are defined in a separate config file - wcf.config.
Nothing fancy here, also many examples available on the web:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<services>
<service name="ServiceBase">
<endpoint address="svc"
binding="basicHttpBinding"
contract="TestWCFNet1.ServiceBasis">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
ServiceBase class is also a very simple - taken from many available examples:
namespace TestWCFNet1
{
[ServiceContract]
public class ServiceBasis
{
[OperationContract]
public double Add(double A, double B) { return A + B; }
[OperationContract]
public double Multiply(double A, double B) { return A * B; }
}
}
If not stated, all classes are in the TestWCFNet1 namespace.
The problem is that although there are no warnings and project builds correctly, IIS Express also starts hosting the service, but then trying to hit any endpoint it always returns 404.
Example log:
Request reached the end of the middleware pipeline without being handled by application code. Request path: GET http://localhost:55201/svc/, Response status code: 404
Tried different variations of urls. Added mex endpoint, but whatever I do I get 404.
When adding this line in the Startup class:
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/test", () => "Hello World");
});
I get a proper response in the browser:
http://localhost:55201/test
"Hello World"
I must admit my knowledge in WCF services is limited. I believe I am doing some simple mistake. But on the other hand, the number of resources on hosting WCF .NET 8.0 services in IIS and configuring them through .config file is also limited.
I would really appreciate any ideas on what could be tried in order to fix the routing to the contract class.
Thank you.
.configfiles anyway. Are you using CoreWCF ? That's a third-party library, not part of ASP.NET Core at all. It has templates that should be used to create new projects and samples that show what CoreWCF projects actually look likemany tutorials available on MS sitethere aren't any, precisely because ASP.NET Core doesn't include WCF. The tutorials are in the CoreWCF Github repo/svcin it. If you check the Core WCF samples you'll see that the client connects tohttp://localhost/CoreWcfSamples/CalculatorService. The service URL is specified in the server project's launchsettings.json, just like any ASP.NET Core site