Moved my ASP.NET website to IIS 8 on windows server 2012... services missing: .svc files are viewable, but their methods give a 404

22,165

Solution 1

OK, I gave up and paid Microsoft $250 for support. With the tech's help, we found the solution, and last night confirmed that it was definitely the solution for all our servers: We disabled SSL altogether for WCF services in the web.config:

<system.serviceModel>
    <bindings>
        <webHttpBinding>
            <binding>
                <security mode="Transport" />

The "Transport" refers to Transport Layer Security (TLS is the new SSL) so HTTPS. Changed that to:

<system.serviceModel>
    <bindings>
        <webHttpBinding>
            <binding>
                <security mode="None" />

Turns out WCF is extremely sensitive to whether you are using HTTP or HTTPS, and if you are using the wrong one you get no helpful errors, just 404.

In my case, both old and new servers were configured to use HTTPS at all times for security. But on the new servers, the SSL (TLS) encryption terminated on the load balancer. In that case encryption only happened between the user's browser and our load balancer, and the traffic between our load balancer and the web servers was unencrypted HTTP.

So the service was listening on HTTPS, and when the request came on HTTP, it just completely ignored it.

(All the other talk about similar issues online focused on uninstalling and reinstalling IIS and ASP.NET and WCF and HTTP Activation and such, so I hope this helps someone. I recommend MS Support if you have a question on the MS stack that SO can't answer in time. It was certainly much cheaper than wasting a few more hours trying to fix it alone).

Solution 2

Please check if your IIS has svc handler added.

WCF services don’t run on IIS 8 with the default configuration, because the webserver doesn’t know, how to handle incoming requests targeting .svc files. You can teach it in two steps:

  1. Add a new MIME type:

Extension: .svc MIME type: application/octet-stream

enter image description here

  1. Add a new Managed HTTP Handler:

    Request path: *.svc Type: System.ServiceModel.Activation.HttpHandler Name: svc-Integrated

enter image description here

Refresh your website/web application

References:

http://gyorgybalassy.wordpress.com/2012/09/24/publishing-a-wcf-service-on-iis8/

http://proq.blogspot.hk/2012/09/wcf-on-iis-and-windows-8.html

http://forums.iis.net/t/1200413.aspx?+svc+missing+can+t+find+Module+to+load+within+Handler+Mapping+IIS+8+0

Solution 3

Just wanted to provide a collection of suggestions in case you haven't tried one of these:

  • Any chance the [OperationContract] is missing for the intended method?
  • Do you have any url rewrites configured in the web.config that could be redirecting the method calls, such as an HTTP/S redirect or some route configuration?
  • Enable Failed Request Tracking in your IIS to see what sub-type of 404 error you are getting? 404.13? something else? It is likely not because something isn't found, but some other error in the request.

Additional Sources:

Solution 4

You can enable tracing/logging in wcf service , so that you can check actual cause of error, if there is mismatch in param or any other thing , directly from error logs.

Refer this to enable tracing, it is just simple config setup - http://msdn.microsoft.com/en-us/library/ms733025(v=vs.110).aspx or How to turn on WCF tracing?

...

Other suggestions:

In ServiceContract, for required method, you have used required attributes. So lets say, Service.svc has servicecontractor defined in IService.cs, and you are concerned about Method. Then Method should be declared like this.

[OperationContract]
[WebGet(UriTemplate = "Method?parameter={value}")]
string AnyMethodName(string value);

Here i have used string as both input and output param type, you can use required type here. Apart from this, you need to have required web.config to have service,binding,endpoint etc. configured properly. Refer - http://msdn.microsoft.com/en-us/library/ms733932(v=vs.110).aspx

So that if you host it in http://www.example.com, then you can execute REST based Get request using http://www.example.com/Service.svc/Method?parameter=XYZ.

More info - http://www.c-sharpcorner.com/UploadFile/b1df45/rest-based-api-using-wcf-services/

Also, as suggested above, there might be some URL rewriting setup, that you have check and fix. or try with https version of URL directly. Or if there is some proxy server that is blocking, has to be checked.

If there is request filtering setup, then check if GET request is blocked there.

Or if at all possible, re-register IIS using aspnet_regiis.exe -iru.

Solution 5

Hope it will help to somebody though its late to reply to this post. I got the same problem and spent hours and hours to find the solution. Finally ended up changing

Luckily I got the answer changing RouteConfig.Cs file as follows From

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

To

routes.IgnoreRoute("{resource}.svc/{*pathInfo}");

as long as you should place your .svc file in root of your application.

That was my own question asked on this link WCF Service throws Http404 on any request except .svc

Share:
22,165
MGOwen
Author by

MGOwen

Working as an ASP.NET Developer. I have a blog, mostly about technology, including some posts about StackExchange: http://mgowen.com

Updated on October 01, 2020

Comments

  • MGOwen
    MGOwen over 3 years

    I moved from IIS 6 on windows server 2003.

    I can browse to the .svc files. I get a nice standard "This is a Windows© Communication Foundation service" page if I go to http://example.com/Service.svc in a browser.

    But I can't browse to any of the methods - I get a 404 error if I go to http://example.com/Service.svc/Method?parameter=xyz in a browser.

    Has anyone seen anything like this? Any ideas or suggestions?

    I thought I might have a similar problem to this question: WCF on IIS8; *.svc handler mapping doesn't work

    But the symptoms are different (looks like they can't see .svc files at all) and none of the solutions work (I have Http Activation for WCF features installed, etc).

  • MGOwen
    MGOwen over 9 years
    Thanks! But I did already try this unfortunately. I found that first link, and followed the instructions - no change. (I did notice that System.ServiceModel.Activation.HttpHandler was not in the dropdown - there were other namespaces in there, but not that, I had to type it in. Any idea if that tells us anything?)
  • Pranav Singh
    Pranav Singh over 9 years
    Its not supposed to be in dropdown. Did you try adding manually?
  • Pranav Singh
    Pranav Singh over 9 years
    Please also check if .Net 4.0 or 4.5 whichever you are using & wcf are installed on server. may be it isn't installed so assemblies are not in GAC.
  • MGOwen
    MGOwen over 9 years
    Yes, I added it manually (typed it into the box like in the screenshot). .Net 4 and WCF are definitely installed on the server, checked that numerous times.
  • Pranav Singh
    Pranav Singh over 9 years
    Please check if this works for you stackoverflow.com/questions/11116134/…
  • MGOwen
    MGOwen over 9 years
    Yes, that's the link I included in the original question, saying I'd tried all of those. As far as I can tell, that issue is where you can't browse to .svc files. I don't have that problem, I just can't see/use the methods of those .svc files.
  • MGOwen
    MGOwen over 9 years
    Yes, as I said, the service works find in the old production server, so ServiceContract, endpoints, bindings, etc are fine. Tracing is a good idea, trying that...
  • Arindam Nayak
    Arindam Nayak over 9 years
    @MGOwen , got your issue reproduced, i have deployed sample WCF app to 2012 server with IIS 8.5, when i browsed HTTPS version of site .svc worked, but when i used .svc/Method?parameter=xyz it did not worked (404 error - same as yours), and later tried same URL with http worked, and found that, i haven't configured WCF app with https, that is why for https version, it shown me 404 error, might be this is the root cause of problem. Conclusion, even if you don't set https for wcf, browsing .svc will work, but not GET request.
  • Arindam Nayak
    Arindam Nayak over 9 years
    @MGOwen, also vice-versa, is true, i.e. if HTTPS is configured in web.config of wcf service, HTTP link will not work, it'll say 404 error. Check if the new server is constantly redirecting to https site and you don't have https enabled in wcf, then probably that is the reason. Use Fiddler or chrome network console to check. msdn.microsoft.com/en-us/library/hh556232(v=vs.110).aspx - set https in web.config.
  • Arindam Nayak
    Arindam Nayak over 9 years
    in the end it turns out to be the issue, that i was telling you in comment to my answer. Just an FYI, in case you missed my comment to my answer post.
  • MGOwen
    MGOwen over 9 years
    Yes (although we'd already solved it by the time you made that comment). Thanks for taking the time to investigate and reproduce the error. Outstanding work, enjoy the bounty!
  • yourbuddypal
    yourbuddypal over 8 years
    Changing my "Transport" to "TransportCredentialOnly" allowed me to test my service using HTTP.
  • VisualBean
    VisualBean about 8 years
    We have a wcf service behind an F5 which transfered https to http behind the scenes.. this fixed it
  • Lzh
    Lzh over 7 years
    Of course! I was doing some WCF tests in a new Web Application project that had all web technologies included (Web API, Web Forms, and... MVC!) Thanks for the heads-up +1
  • AxelWass
    AxelWass about 7 years
    I had to install also the feature .NET Framework | WCF Services | HTTP Activition