views:

38

answers:

1

I'm attempting to use jQuery to access a method in an asmx webservice. When I try to execute the below jquery call, I get an error 'MyNameSpace' is undefined.

jquery call to webservice:

  MyNameSpace.MyWebService.MyMethod(parameter, function (e) { alert('Success') }, function (e) { alert('Failure') });

scriptmanager:

  <asp:ScriptManager id="ScriptManager1" runat="server" >
     <Services>
       <asp:ServiceReference path="MyWebService.asmx" />
     </Services>
  </asp:ScriptManager>

MyWebService.asmx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Security;
using System.Web.Script.Services;


namespace MyNameSpace{
    [ScriptService]
    [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 MyWebService : System.Web.Services.WebService
    {


        [WebMethod]
        public void MyMethod(string parameter)
        {
            //do some cool stuff


        }
    }
}
+1  A: 

This turned out to be a problem with my .asmx file and the fact that I had moved it into a different folder. To fix my .asmx file, i right click on it and selected view markup. The class property was set to the wrong class so my scriptmanager couldn't load it.

SLoret