0

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]

3
  • can you provide the actual calling getting made, such as the URL, and also the error? Is it a 500 or 404 error? Commented Feb 16, 2009 at 14:20
  • It isn't an error that's visible in the browser. I only found out about it using Firefox's Error console. But the web method isn't being called as a result. The error in Error Console says: Error: QCApp4 is not defined Source File: localhost:2507/Sheet.aspx Line: 153 Commented Feb 16, 2009 at 14:31
  • What do you mean by the actual calling? I'm calling a Web Method in the same project as the web page calling from. According to what I've read I can just make the call as if I was calling a Javascript function. Am I incorrect in that assumption? Commented Feb 16, 2009 at 14:33

2 Answers 2

2

If you set the InlineScript attribute on the ServiceReference element, it'll write out the JavaScript methods inline with the HTML so you can see exactly what you need to call or if you're calling the wrong thing:

<asp:ScriptManager ID="ScriptManager1" runat="server">
    <Services>
        <asp:ServiceReference Path="~/SavingService.asmx" InlineScript="true" />
    </Services>
</asp:ScriptManager>
Sign up to request clarification or add additional context in comments.

Comments

1

I screwed up two things with this. I went back and found the video I had previously watched on setting these web services up.

I realized, I had accidentally made the web method static, and also forgotten to add the callback method parameters. Once I added a on complete and an on error handler, it worked fine, no errors in the Error Console.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.