wcf and json 404 error

Last post 11-09-2009 6:07 PM by Andrew Wang - MSFT. 1 replies.

Sort Posts:

  • wcf and json 404 error

    11-03-2009, 6:19 PM
    • Member
      point Member
    • dev14
    • Member since 11-03-2009, 11:17 PM
    • Posts 1

    I'm trying to call the WCF service(Different machine) from my local machine but no luck, returns 404

    I want to call the same service using VS2005


    there may be simple things missing but as I'm new to this couldn't figure out.

    1. WCFService.svc

    namespace WCFTest
    {
       
        public class WCFService : IWCFService
        {
            public string HelloWorld(string strName)
            {
                return "Your Entered:"+strName;
            }
        }
    }

    2. WCFService.svc.cs

    namespace WCFTest
    {
       
        [ScriptService]
        public class WCFService : IWCFService
        {
            public string HelloWorld(string strName)
            {
                return "Your Entered:"+strName;
            }
        }
    }

    3. webconfig

        <system.serviceModel>
            <bindings>
                <webHttpBinding>
                    <binding name="jsonBinding" maxReceivedMessageSize="2147483647">
                    </binding>
                </webHttpBinding>
            </bindings>
            <services>
                <service behaviorConfiguration="WCFTest.WCFServiceBehavior" name="WCFTest.WCFService">
                    <endpoint address="http://server:portnumber/WCFService.svc" binding="webHttpBinding" bindingConfiguration="jsonBinding" behaviorConfiguration="jsonBehavior" name="myservice" contract="WCFTest.IWCFService">
                    </endpoint>
                </service>
            </services>
            <behaviors>
                <serviceBehaviors>
                    <behavior name="WCFTest.WCFServiceBehavior">
                        <serviceMetadata httpGetEnabled="true"/>
                        <serviceDebug includeExceptionDetailInFaults="false"/>
                    </behavior>
                </serviceBehaviors>
                <endpointBehaviors>
                    <behavior name="jsonBehavior">
                        <enableWebScript/>
                    </behavior>
                </endpointBehaviors>
            </behaviors>
        </system.serviceModel>


    ** The service is deployed on the server.

    4. Created Defalut.aspx on my local machine

    <body onload="Initialize();">
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
            <Services>
                <asp:ServiceReference Path="http://server:portnumber/WCFService.svc"/>
            </Services>
            <Scripts>
                <asp:ScriptReference Path="~/test.js"/>
            </Scripts>
        </asp:ScriptManager>
        <div>
        <label>Greetings:</label><asp:Label ID="lblShow" runat="server"></asp:Label>
        </div>
        </form>
    </body>

    5. Created test.js on my local machine

    function Initialize() {
        var proxy = new WCFTest.IWCFService();
        proxy.HelloWorld("YOurName",OnSuccess, OnFailure);
    }

    function OnSuccess(result) {
        document.getElementById('lblShow').innerHTML = result;
    }

    function OnFailure(result) {
        alert('Failed');
    }

    6. Result: "The server method 'HelloWorld' failed."

    Using Firebug:

    **Response Headers

    Server    ASP.NET Development Server/9.0.0.0
    Date    Tue, 03 Nov 2009 20:48:12 GMT
    Content-Length    1210
    Connection    Close


    **Request Headers

    Host    localhost:4007
    User-Agent    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.4) Gecko/20091016 Firefox/3.5.4 (.NET CLR 3.5.30729)
    Accept    text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language    en-us,en;q=0.5
    Accept-Encoding    gzip,deflate
    Accept-Charset    ISO-8859-1,utf-8;q=0.7,*;q=0.7
    Keep-Alive    300
    Connection    keep-alive
    Content-Type    application/json; charset=utf-8
    Referer    http://localhost:4007/MyTest/Default.aspx
    Content-Length    20

    **POST
    {"strName":"YOurName"}

    **Response

    <html>
        <head>
            <title>Not Found</title>
            <style>
                body {font-family:"Verdana";font-weight:normal;font-size: 8pt;color:black;}
                p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
                b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
                h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
                h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
                pre {font-family:"Lucida Console";font-size: 8pt}
                .marker {font-weight: bold; color: black;text-decoration: none;}
                .version {color: gray;}
                .error {margin-bottom: 10px;}
                .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
            </style>
        </head>
        <body bgcolor="white">

                <span><h1>Server Error in '/MyTest' Application.<hr width=100% size=1 color=silver></h1>

                <h2> <i>HTTP Error 404 - Not Found.</i> </h2></span>

                <hr width=100% size=1 color=silver>

                <b>Version Information:</b>&nbsp;ASP.NET Development Server 9.0.0.0

                </font>

        </body>
    </html>


    The URL it is trying to hit is

    POST http://localhost:4007/WCFService.svc/HelloWorld

    thanks.

    Filed under:
  • Re: wcf and json 404 error

    11-09-2009, 6:07 PM

    Let's debug this one step at a time.

    How is your IWCFService defined? 

    Could you put a simple Get method on your service, and use a web browser to see if you can HTTP GET anything from your service?  This way we can find out if your IIS host is working properly.

Page 1 of 1 (2 items)
Microsoft Communities