WCF Web Service Method - Resource Not Found

Discussion in 'Site Programming, Development and Design' started by chapmanjw, Oct 7, 2010.

  1. Hello,

    I am using .NET 4 and I am using WCF web services to interact with data via AJAX on my pages. When I try to connect to the service with the method name, I get a 404 Resource Cannot Be Found error message.

    i.e.: www.domain.com/servicename.svc/MethodName

    On my DEV server and on in the VS test server, it works just fine.

    Any ideas?
  2. Ray


    What happens when you call on www.domain.com/servicename.svc? Does it also give a 404 error?

    What is your application suppose to do when it calls on www.domain.com/servicename.svc/MethodName?

    Did you make sure you uploaded the assembly in the Bin folder?

    I am also suspecting that you also have something installed on your computer that is making this work. Do you know the name of the component or assembly it is trying to call on. Hopefully it is Bin deployable which means you can simply upload it to your Applications Bin folder and your application should be able to reference it from there.
  3. It does not give me a 404 error when going to www.domain.com/servicename.svc, it gives me the generic WCF message about consuming it.

    When calling www.domain.com/servicename.svc/MethodName it is supposed to return some data in JSON format.

    It works on my local machine AND on a test server that I have. On the test server, I only have a base install on Win 2008 R2 with .NET 4, IIS, and antivirus. I have not installed anything else on that server.

    The problem that I see is that IIS is not recognizing the /MethodName as a method. It thinks its a folder.
  4. Here is an example WCF service to consider: https : // account.notibot.com/services/Registration.svc/GetIPAddress
  5. Ray


    What are the endpoints you coded this to be?
  6. Not sure exactly what you are wanting to know, so here is that section of my web.config (hopefully that gives you the answer you are looking for):

    <service name="Notibot.WWW.services.Registration">
    <endpoint address="" behaviorConfiguration="Notibot.WWW.services.RegistrationAspNetAjaxBehavior"
    binding="webHttpBinding" contract="Notibot.WWW.services.Registration"></endpoint>
    <add baseAddress="https://account.notibot.com/"/>
    <add baseAddress="http://account.notibot.com/"/>
    <add baseAddress="http://localhost/"/>
    <add baseAddress="http://ra/"/>
    <service name="Notibot.WWW.services.Maintenance">
    <endpoint address="" behaviorConfiguration="Notibot.WWW.services.MaintenanceAspNetAjaxBehavior"
    binding="webHttpBinding" contract="Notibot.WWW.services.Maintenance"></endpoint>
    <add baseAddress="https://account.notibot.com/"/>
    <add baseAddress="http://account.notibot.com/"/>
    <add baseAddress="http://localhost/"/>
    <add baseAddress="http://ra/"/>
    <behavior name="Notibot.WWW.services.RegistrationAspNetAjaxBehavior">
    <enableWebScript />
    <behavior name="Notibot.WWW.services.MaintenanceAspNetAjaxBehavior">
    <enableWebScript />
    <behavior name="">
    <serviceMetadata httpGetEnabled="true" />
    <serviceDebug includeExceptionDetailInFaults="false" />
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
    <add prefix="http://localhost"/>
    <add prefix="http://localhost/services"/>
    <add prefix="http://ra"/>
    <add prefix="http://ra/services"/>
    <add prefix="https://account.notibot.com"/>
    <add prefix="https://account.notibot.com/services"/>

    Also, here is the example Method I am working with (none of them work in the hosted environment, but this is the simplest one):

    [WebGet(ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
    public string GetIPAddress()
    string result = string.Empty;
    OperationContext content = OperationContext.Current;
    MessageProperties messageProperties = content.IncomingMessageProperties;
    RemoteEndpointMessageProperty endpointProperty = messageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;

    result = endpointProperty.Address;
    catch (Exception ex)
    result = ex.ToString();
    return result;
  7. Ray


    The 404 error is really quite clear. I am suspecting a class or some kind of method it cannot find. I'm leaning to "<service name="Notibot.WWW.services.Maintenance">" but I'm just not sure.

    Try downloading a program called Fiddler.


    It should log the calls it makes and thus give you a little more detail on what it is not finding.

    You said it works on your computer, but did you install anything on your computer or installed something in your own GAC? One of the most common misperception is that all the assemblies installed on a customers development box will also be on the Winhost web servers. Unfortunately that is simply not the case.
    Last edited by a moderator: Oct 14, 2015
  8. On the development server, the only thing installed to the GAC is the MySQL client libraries. This service isn't talking to or referencing MySQL.

    Fiddler comes back with a normal 200 response because IIS is giving a valid page back (the error page), which has:

    Server Error in '/' Application.

    The resource cannot be found.

    Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

    Requested URL: /services/Registration.svc/GetIPAddress

    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

    What it appears to be is that IIS is not recognizing the WCF binding properly. What would most likely resolve the issue is to run the service model registration tool from .NET 4.0 (as described here: http://blogs.msdn.com/b/davidwaddleton/archive/2007/11/02/wcf-and-404-3-errors.aspx, except the version in the v4.0 folder would need to be used instead of the v3).
  9. Ray


    The ling/blog you provided assumes that WCF is not installed on the server. I can assure you that it is installed otherwise we will see a lot more complaints about WCF not working properly on the server.

    Also try looking at this thread from our forum.

    Last edited by a moderator: Oct 14, 2015
  10. I have no doubt that WCF is on the server, I just dont think the bindings are working or configured properly (running the registration command would fix that).

    I tried the IgnoreRoutes idea just now and it does the same thing.
  11. Ray


  12. Another happy ending.

Share This Page