I'm trying to call a ASP.NET web service from Javascript, and it won't recognize the Web Method, even when I fully qualify the name, I'm trying to figure out what is wrong.
Here is the part of my web.config file:
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
</httpHandlers>
Here is my web service declarations
[WebService(Namespace = "http://tempuri.org")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class SavingService : System.Web.Services.WebService
{
[WebMethod]
public static void SaveToDB(string runCode, string container,
string productType, string inspector, string[][] scoregrid, string notes)
and here is the javascript (QCApp4 is my project's namespace):
function PrepToSave()
{
....
QCApp4.SavingService.SaveToDB(codev, containerv, prodtype, inspector, scoregrid, notes);
}
scoregrid is declared on the js side as a jagged 2d array using the Array() command. That was the only worry I had with regard to the parameters of the web service.
And here is the service reference:
<asp:ScriptManager id="scriptmng" runat="server">
<Services>
<asp:ServiceReference Path="~/SavingService.asmx" />
</Services>
</asp:ScriptManager>
I get errors whether I call the web method directly, or call it like SavingService.SaveToDB, or with the full Qualifiers. The error I get says that SaveToDB is not defined. SavingService is not defined, QCApp4 is not defined, depending on what the first part of the qualified name is entered as.
Am I missing something? Is there something I've set incorrectly?
It turns out I had made my WebMethod static, of course now I'm getting an error in the error console of:
Error: [Exception... "'Sys.Net.WebServiceFailedException: Sys.Net.WebServiceFailedException: The server method 'SaveToDB' failed with the following error: System.NullReferenceException-- Object reference not set to an instance of an object.' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "" data: no]