CoreWCF icon indicating copy to clipboard operation
CoreWCF copied to clipboard

CoreWCF on IIS Hosting inside site folder not working

Open alexvazquez opened this issue 2 years ago • 3 comments

I have a CoreWCF Service with about 12 endpoints working perfectly locally using HTTPS.

I deployed to production using IIS in a site app.mydomain.com inside a subfolder corewcfservice. The application pool set to No Managed Code. When trying to access the https://app.mydomain.com/corewcfservice/util.svc it never resolved. I get 404 errors.

In my program.cs I declare the endpoints as follows:

  serviceBuilder.AddService<Util>();
  serviceBuilder.AddServiceEndpoint<Util, IUtil>(customBinding, "/Util.svc");

Then what I did was to create a new site svc.mydomain.com and publish my files into the root folder. By doing this it worked fine when I hit https://svc.mydomain.com/util.svc

By some extrange reason or maybe I don't know the right way to publish in a subfolder, CoreWCF doesn't allow to publish inside a subfolder. I even tried to recompile the project and declare the endpoints like this:

  serviceBuilder.AddService<Util>();
  serviceBuilder.AddServiceEndpoint<Util, IUtil>(customBinding, "/corewcfservice/Util.svc");

I deployed to IIS in the corewcfservice subfolder and still doesn't work.

Any clue on how to publish and have the endpoints listen and resolve inside a subfolder?

alexvazquez avatar May 14 '23 00:05 alexvazquez

Not specific to this issue, but this what I would suggest. We use this approach for publishing multiple regular .Net6 WebAPI on IIS, under a single website, using inprocess IIS hosting. Create application with name corewcfservice in IIS and map that your deployed subfolder. Within your code, just add binding for /Util.svc. The application name becomes part of full URL - https://websiterootfqdn/appname/whateverservice.svc

askids avatar May 21 '23 18:05 askids

Hi alexvazquez,

try this code, it worked for me:

serviceBuilder.AddService<Util>(serviceOptions =>
{
    serviceOptions.DebugBehavior.HttpsHelpPageEnabled = true;
    serviceOptions.BaseAddresses.Add(new Uri("https://localhost/corewcfservice/Util.svc"));
});
serviceBuilder.AddServiceEndpoint<Util, IUtil>(customBinding, string.Empty);

you should now be able to hit the URL at "YOURSERVER/corewcfservice/Util.svc"

Don't forget to add this singleton which translates 'localhost' to 'YOURSERVER':

builder.Services.AddSingleton<IServiceBehavior, UseRequestHeadersForMetadataAddressBehavior>();

Your mileage may vary. Maybe some changes to urls are necessary to fully work.

drpdrp avatar Jun 13 '23 14:06 drpdrp

Hi alexvazquez,

try this code, it worked for me:

serviceBuilder.AddService<Util>(serviceOptions =>
{
    serviceOptions.DebugBehavior.HttpsHelpPageEnabled = true;
    serviceOptions.BaseAddresses.Add(new Uri("https://localhost/corewcfservice/Util.svc"));
});
serviceBuilder.AddServiceEndpoint<Util, IUtil>(customBinding, string.Empty);

you should now be able to hit the URL at "YOURSERVER/corewcfservice/Util.svc"

Don't forget to add this singleton which translates 'localhost' to 'YOURSERVER':

builder.Services.AddSingleton<IServiceBehavior, UseRequestHeadersForMetadataAddressBehavior>();

Your mileage may vary. Maybe some changes to urls are necessary to fully work.

Thansk @drpdrp this works for me.

alfonsovgs avatar Sep 08 '23 22:09 alfonsovgs