title: WCF Newbie Question: Calling Methods from JavaScript
body: <p>Greetings!</p>
  
  <p>I'm new to WCF and I thought it would be similar to ASP.NET web services, but I'm unable to call a method from client-side JavaScript.  My web form looks like this:</p>
  
  <pre><code>&lt;form id="form1" runat="server"&gt;
     &lt;div&gt;
        &lt;asp:ScriptManager ID="ScriptManager1" runat="server"&gt;
           &lt;Scripts&gt;
              &lt;asp:ScriptReference Path="~/test.js" /&gt;
           &lt;/Scripts&gt;
           &lt;Services&gt;
              &lt;asp:ServiceReference Path="~/MyService.svc" /&gt;
           &lt;/Services&gt;
        &lt;/asp:ScriptManager&gt;
     &lt;/div&gt;
     &lt;button onclick="test()"&gt;Click Me&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>My service's interface looks like this:</p>
  
  <pre><code>namespace Test
  {
      [ServiceContract(Namespace = "Test")]
      public interface IMyService
      {
          [OperationContract]
          void DoWork();
  
          [OperationContract]
          string SayHi();
      }
  }
  </code></pre>
  
  <p>And here's its implementation:</p>
  
  <pre><code>namespace Test
  {
      [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
      public class MyService : IMyService
      {
          public void DoWork()
          {
          }
  
          public string SayHi()
          {
              return "Hello, World!";
          }
      }
  }
  </code></pre>
  
  <p>And finally the JavaScript:</p>
  
  <pre><code>function test() {
      Test.MyService.SayHi(SayHiSuccess, SayHiError);
  }
  
  function SayHiSuccess(result) {
      alert(result[0]);
  }
  
  function SayHiError(error) {
      alert(error.toString());
  }
  </code></pre>
  
  <p>It appears that the service's SayHi() method never executes, although I'm not sure why or how to being troubleshooting.  Any suggestions?</p>