开发者

.NET 4 WCF REST service 404 on some requests

开发者 https://www.devze.com 2023-02-18 13:59 出处:网络
I have a .NET 4.0 WCF REST service (to generate and validate product keys) that I\'ve set up on my hosting with Arvixe (via Web Deploy in Visual Studio). Locally on my Windows 7 machine it runs fine f

I have a .NET 4.0 WCF REST service (to generate and validate product keys) that I've set up on my hosting with Arvixe (via Web Deploy in Visual Studio). Locally on my Windows 7 machine it runs fine from IIS but on my hosting I get 404 errors from all except the base service URL. For example:

  • "http://www.mydomain.com/LicensingServer/" - works as expected with a browser request returning a response (with or without the querystring parameters)
  • "http://www.mydomain.com/LicensingServer/help" - 404 returned with default WCf help page turned on in the web.config
  • "http://www.mydomain.com/LicensingServer/validate" - 404 returned from a browser request (with or without the query string parameters)

My methods are defined as:

[WebGet(UriTemplate = "?bla={bla}&etc={etc}")]  
public Stream GetLicenseKey(string bla, string etc)

[WebGet(UriTemplate = "/validate?item={item}")]  
public Stream ValidateLicense(string item,)

My Global.ascx has:

RouteTable.Routes.Add(new ServiceRoute("", new WebServiceHostFactory(), typeof(LicensingService)));

My web.config is pretty much the standard template that the wizard generated but I have added:

runAllManagedModulesForAllRequests="true"

I've tried adding several new handlers in the web.config for ".svc" (this one already existing in the IIS manager), ".*" and "*" but none have helped. I also trie开发者_C百科d adding a baseAddressPrefixFilter with prefix="http://www.mydomain.com/" as suggested in the Arvixe forums but that also made no difference.

I also turned on WCFTrace logging but so far I've been unsuccessful in getting the log file from the server, it shows as an empty 0b file when I download it but a 280kb on the server.

I'm guessing this is just a simple configuration issue but I've run out of ideas. I can't understand why it runs fine on my local (very basic install) of IIS but not on my hosting.

I realise there are other questions here on stackoverflow but I've been throw a large number of them and tried many of the suggestions without resolving this issue. A lot of the resolutions relate to adding the hanlders to the web.config that I have tried.

Can anyone tell me what is wrong or give me an idea where to look next?

Thanks.


Check this post : http://pranayamr.blogspot.com/2011/03/rest.html might help you to resolve your issue easily.

As i can see there is no need of this

RouteTable.Routes.Add(new ServiceRoute("", new WebServiceHostFactory(), typeof(LicensingService)));

just check the above link for more detail


The solution turns out to be rather obvious. I'm hosting the WCF service in a virtual directory where the root website has Wordpress installed. Wordpress adds URL Rewrites and these were preventing me from accessing the services. I added an 'exclusion' type rule and now it all works. I was so wrapped up in the WCF configuration side of things that this didn't even occur to me, I'd resorted to going through each page of IIS settings and comparing it to my local copy.

0

精彩评论

暂无评论...
验证码 换一张
取 消