0

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.App
  • Microsoft.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.

8
  • 1
    ASP.NET Core doesn't have a WCF template. WCF wasn't migrated to .NET Core at all, and .NET (Core) doesn't use .config files 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 like Commented Dec 5, 2024 at 16:11
  • Yes, I am using CoreWCF. Just to note to others: regarding AddServiceModelConfigurationManagerFile("wcf.config") call, I noticed that wcf.config file is never read (no attempt to parse it). Commented Dec 5, 2024 at 16:54
  • I already explained that .NET Core doesn't use *.config files. Nor does SOAP/WCF use HTTP endpoints. Did you actually check the CoreWCF samples? How was this project created? many tutorials available on MS site there aren't any, precisely because ASP.NET Core doesn't include WCF. The tutorials are in the CoreWCF Github repo Commented Dec 6, 2024 at 8:10
  • Check the Basic HTTP sample to see what the server and client should look like. SOAP doesn't use GET, all requests are made using a POST request containing very specific headers and XML content using standardized schemas. You can't just make a GET call to a SOAP service, no matter what it's written in. Commented Dec 6, 2024 at 8:14
  • If you want a Postman-like tool to test SOAP services check SoapUI. When you post the URL of the WSDL file it will inspect the service definition and show you the available operations, DTOs and allow you to call the operations with well-formed test data. The URL does not include /svc in it. If you check the Core WCF samples you'll see that the client connects to http://localhost/CoreWcfSamples/CalculatorService. The service URL is specified in the server project's launchsettings.json, just like any ASP.NET Core site Commented Dec 6, 2024 at 8:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.