title: Calling a WebService from JQuery $.ajax gets Error 500
body: <p>I'm struggling with my first WebService, so I decided to strip everything down to the basics. Still not working.</p>
  
  <p>I created a brand new ASP.NET Website project.</p>
  
  <p>I added a folder named WebService. In the WebService folder, I added a new WebService using the ASP.NET template.  I modified the template only to uncomment the  [System.Web.Script.Services.ScriptService].</p>
  
  <p>In the Default.aspx page, after the "Welcome to ASP.NET", I added a panel as follows:</p>
  
  <pre><code>&lt;asp:Panel ID="Panel1" runat="server" Height="200px" Width="200px" BackColor="Blue" onclick="HelloWorld();"&gt;
  &lt;/asp:Panel&gt;
  </code></pre>
  
  <p>I also added the following scripts to the HeaderContent area:</p>
  
  <pre><code>&lt;script type="text/javascript" language="Javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
  
      function OnSuccessCall(response) {
          alert("Success! : " + response);
      }
      function OnErrorCall(response) {
          alert(response.status + " " + response.statusText);
      }
      function HelloWorld() {
          var pageUrl = '&lt;%=ResolveUrl("~/WebService/WebService.asmx")%&gt;'
  
          $.ajax({
              url: pageUrl + "/HelloWorld",
              success: OnSuccessCall,
              error: OnErrorCall
          });
      }
  
   &lt;/script&gt;
  </code></pre>
  
  <p>When I run this code, I get Error 500.  What am I missing?</p>
  
  <p>//-------------------------------  UPDATE  ----------------------------------------------</p>
  
  <p>Ahh! A new clue! If  move the WebMethod into the code-behind for Default.aspx, not as part of a WebService class but just as a method with a [WebMethod] attribute, it works. (At least I get to my OnSuccess function OK).  However, if I then add </p>
  
  <pre><code>contentType: "application/json; charset=utf-8",
  dataType: "json",
  </code></pre>
  
  <p>to the $.ajax() call, I'm back to getting my Error 500 (although it might be for a different reason).  Is there some install piece that I'm missing for JSON or something?</p>
  
  <p>//-------------------------------  UPDATE  ----------------------------------------------
  Here's the actual WebService. As I stated before, its exactly what you get when you create a New Item and select Web Service.</p>
  
  <p>If someone can just tell me that this works for them, then I can focus on environment issues.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Services;
  
  /// &lt;summary&gt;
  /// Summary description for WebService
  /// &lt;/summary&gt;
  [WebService(Namespace = "http://tempuri.org/")]
  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
   [System.Web.Script.Services.ScriptService]
  public class WebService : System.Web.Services.WebService {
  
      public WebService () {
  
          //Uncomment the following line if using designed components 
          //InitializeComponent(); 
      }
  
      [WebMethod]
      public string HelloWorld( ) {
          return "Hello World";
      }
  
  }
  </code></pre>