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

好久不见. 提交于 2019-12-18 03:32:10

问题


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).


回答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).




回答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

  1. Add a new Managed HTTP Handler:

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

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




回答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:

  • http://www.iis.net/learn/troubleshoot/using-failed-request-tracing/troubleshooting-failed-requests-using-tracing-in-iis
  • WCF service returning 404 on method reqests
  • https://social.msdn.microsoft.com/Forums/vstudio/en-US/7d69a209-489e-486c-81f4-a660c539ae49/wcfiis-7-returns-404-but-only-for-some-method-arguments?forum=wcf
  • https://social.msdn.microsoft.com/Forums/vstudio/en-US/7d69a209-489e-486c-81f4-a660c539ae49/wcfiis-7-returns-404-but-only-for-some-method-arguments?forum=wcf



回答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.




回答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



来源:https://stackoverflow.com/questions/26398049/moved-my-asp-net-website-to-iis-8-on-windows-server-2012-services-missing-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!