title: ExtJS 4: Ext.Ajax.request error "Web Service method name is not valid."
body: <p>What would cause this?</p>
  
  <pre><code>Error System.InvalidOperationException: UpdateProject Web Service method name is not valid.
  
     at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
  
     at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean&amp; abortProcessing)
  </code></pre>
  
  <p>JavaScript Code:</p>
  
  <pre><code>                Ext.Ajax.request({
                          url: 'http://localhost/Controls/ProjectList/ProjectListService.asmx/UpdateProject',
                          params: {
                              'project': { project_id: 'a', project_number: 'b', project_name: 'c' }
                          },
                          success : function(response){
                              alert(response.responseText);
                          }, 
                          failure : function(response){
                              alert("Error " + response.responseText);
                          }
                  });                         
  </code></pre>
  
  <p><strong>Web Service (ProjectListService.asmx):</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Services;
  using System.Xml;
  using System.Data;
  using System.Web.Script.Services;
  using System.IO;
  using System.Text;
  
  namespace Web.Controls.ProjectList
  {
      /// &lt;summary&gt;
      /// Summary description for WebService1
      /// &lt;/summary&gt;
      [WebService(Namespace = "http://tempuri.org/")]
      [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
      [System.ComponentModel.ToolboxItem(false)]
      // 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 ProjectListService : System.Web.Services.WebService
      {
          [Serializable]
          public class Project
          {
              public string project_id;
              public string project_number;
              public string project_name;
          }
  
          [WebMethod]
          [ScriptMethod(ResponseFormat = ResponseFormat.Json,
              UseHttpGet = false, XmlSerializeString = false)]
          public List&lt;Project&gt; GetProjects(string myTest, string bar)
          {
              var list = new List&lt;Project&gt;(new[] {
                  new Project() {project_id="1", project_name="project 1", project_number="001"},
                  new Project() {project_id="2", project_name= "project 2", project_number= "002" },
                  new Project() {project_id="3", project_name= "project 3", project_number= "003" }
              });
  
              return list;
          }
  
          [WebMethod]
          [ScriptMethod]
          //[ScriptMethod(ResponseFormat = ResponseFormat.Json,
          //    UseHttpGet = false, XmlSerializeString = false)]
          public void UpdateProject(Project project)
          {
  
              string x = "";
              Project p = project;
  
          }
      }
  }
  </code></pre>
  
  <p>==========================</p>
  
  <h1>7/20/2012 @ 10:43 update:</h1>
  
  <p><strong>New Error:</strong></p>
  
  <pre><code>Error {"Message":"Invalid JSON primitive: project.","StackTrace":"   at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()\r\n   at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n   at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)\r\n   at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n   at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)\r\n   at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)\r\n   at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n   at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.ArgumentException"}
  </code></pre>
  
  <p><strong>JavaScript Code:</strong></p>
  
  <pre><code>                Ext.Ajax.request({
                          url: 'http://localhost/Controls/ProjectList/ProjectListService.asmx/UpdateProject',
                      headers: { 'Content-Type': 'application/json' },
                      method: 'POST',
                      scope: this,
                          params: {
                              'project': { project_id: 'a', project_number: 'b', project_name: 'c' }
                          },
                          success : function(response){
                              alert(response.responseText);
                          }, 
                          failure : function(response){
                              alert("Error " + response.responseText);
                          }
                  });  
  </code></pre>
  
  <p>==================================                       </p>
  
  <h1>7/20/2012 @ 2:40pm update:</h1>
  
  <p><strong>Working JSON Request:</strong></p>
  
  <pre><code>                var jsonStr = Ext.encode({ 'project_id': 'a', 'project_number': 'b', 'project_name': 'c' });
  
                  Ext.Ajax.request({
                          url: 'http://localhost/Controls/ProjectList/ProjectListService.asmx/SaveProject',
                      method: 'POST',
                          jsonData: jsonStr,
                          success : function(response){
                              alert(response.responseText);
                          }, 
                          failure : function(response){
                              alert("Error " + response.responseText);
                          }
                  });  
  </code></pre>
  
  <p><strong>Web Method (so far):</strong></p>
  
  <p>(see Project object above in question)</p>
  
  <pre><code>[WebMethod]
  [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = false, XmlSerializeString = false)]
  public string SaveProject()
  {         
      return "success";
  }
  </code></pre>
  
  <p>================================</p>
  
  <h1>7/22/2012 @ 9:03pm update (fixed):</h1>
  
  <p>Changed two things.  Added the "project" parameter of type "Project" for my web service.  Then put the Project object properties inside of that object in my "jsonData" object.</p>
  
  <p><strong>Working JSON Request:</strong></p>
  
  <pre><code>            //var jsonStr = Ext.encode({ 'project_id': 'a', 'project_number': 'b', 'project_name': 'c' });
              var jsonDataObject = { 'project': { 'project_id: '4', 'project_number': '004', 'project_name': 'project 4' } };
  
              Ext.Ajax.request({
                          url: 'http://localhost/Controls/ProjectList/ProjectListService.asmx/SaveProject',
                  method: 'POST',
                          jsonData: jsonDataObject,
                          success : function(response){
                              alert(response.responseText);
                          }, 
                          failure : function(response){
                              alert("Error " + response.responseText);
                          }
              });  
  </code></pre>
  
  <p><strong>Web Method (so far):</strong></p>
  
  <p>(see Project object above in question)</p>
  
  <pre><code>[WebMethod]
  [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = false, XmlSerializeString = false)]
  public string SaveProject(Project project)
  {         
      return "success";
  }
  </code></pre>