Issue encountered while making requests to ASP.NET web services using Javascript

Having some trouble making a call to an ASP.NET web service from Javascript here. No matter how I fully qualify the name, it just won't recognize the Web Method - trying to troubleshoot this.

Snippet 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>

Next up is the 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)

JavaScript code (QCApp4 represents the project's namespace):

function PrepToSave()
{
    ....
    QCApp4.SavingService.SaveToDB(codev, containerv, prodtype, inspector, scoregrid, notes);
}

On the javascript side, scoregrid is set as a jagged 2d array using Array(). This seemed to be the only concern with the parameters for the web service.

Lastly, the service reference:

<asp:ScriptManager id="scriptmng" runat="server">
<Services>
<asp:ServiceReference Path="~/SavingService.asmx" />
</Services>
</asp:ScriptManager>

Encountering errors whether calling the web method directly, through SavingService.SaveToDB, or with full qualifiers. The error message points out that SaveToDB isn't defined, and similar issues with the other parts of the qualified name depending on what's entered first.

Could I be overlooking something? Any incorrect settings on my end?

Realized the WebMethod was set as static which caused more problems, currently seeing this in the error console:

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]

Answer №1

Enabling the InlineScript attribute on the ServiceReference element allows the JavaScript methods to be written directly into the HTML, providing a clear view of what needs to be called or if there are any errors in the calls:

<asp:ScriptManager ID="ScriptManager1" runat="server">
    <Services>
        <asp:ServiceReference Path="~/SavingService.asmx" InlineScript="true" />
    </Services>
</asp:ScriptManager>

Answer №2

There were two mistakes I made in this process. After reviewing the video on setting up these web services, I discovered my errors.

I had mistakenly set the web method as static and forgot to include the callback method parameters. Once I added an on complete and an on error handler, everything worked smoothly with no errors appearing in the Error Console.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Hide the modal popup when the button inside the modal is clicked

I have a situation where I am using a usercontrol in a modal popup. Here is the code snippet: <ajt:ModalPopupExtender OkControlID="btnOk" runat="server" PopupControlID="pnlViewOrderItems" ID="mpxViewItems" TargetControlID="btnOk" ...

Debouncing form inputs in VueJS with LoDash debounce on the entire form

I'm currently experimenting with implementing LoDash debounce to detect when a user stops typing on a form and trigger an event accordingly. Looking for inspiration from this helpful guide However, my goal is to extend this functionality to cover al ...

"Encountering a problem with the client-session middleware: the value of req.session_state is becoming undefined

I'm facing an issue with client-session middleware in Express. After setting the session_state, it doesn't seem to be accessible when redirecting to a new route. I followed a tutorial on YouTube (client-session part starts at around 36:00) and do ...

Guide on incorporating a Python script into a website using DJango

I am new to Django and looking for guidance. My goal is to have users input text in an HTML textbox, then process that text using Python and display it on the website. Despite going through documentation and tutorials, I have not been successful in gettin ...

Incorporating parsley.js validation into ASP.NET form inputs

My .aspx file contains a large form section with various elements, both html and < asp: > tags. The form functions correctly, but when I attempt to implement parsley validation, it fails due to the nested forms. Despite this issue, the form works fin ...

Node.js - Passport authentication consistently results in redirection to failure route

I am currently working on creating a login form using passportJs, but I keep encountering the issue of failureRedirect. Despite searching on stack overflow for a solution, I have not found the correct answer yet. Below is my code: Here is how I am crea ...

Having trouble with Google font displaying on React site but not on mobile devices?

After importing a Google font that appears perfectly on desktop and cross-browser, an issue arises on mobile where default fonts are shown instead. Below is a snippet from my App.css file: @import url("https://fonts.googleapis.com/css2?family=Turret+Ro ...

Upgrade your react-select by replacing the DropdownIndicator with a modern CSS triangle design

I am a beginner in React and JS, and I am facing a challenge that I need to solve. My task is to replace the DropdownIndicator with a CSS triangle. While I have come across some similar issues (such as this one https://github.com/JedWatson/react-select/iss ...

Seeking assistance with iterating through a specific JSON data structure

I am dealing with JSON data that has a specific format: {"errors":{"toDate":["Date error_message"],"name":["name error_message"]}} OR {"success":{"toDate":["Date update_data"],"name":["name update_data"]}} I am looking for a way to loop through this d ...

What is the reason for node executing both of these handlers on the server?

My node app is set up with two handlers, one for requests to the root URL and another for the slug. However, when I visit the root or slug URLs, the app crashes and I receive this error: url is pointing to root url has a slug throw err; // Rethrow non-MySQ ...

Neglecting the inclusion of a property when verifying for empty properties

In the code snippet below, I have implemented a method to check for empty properties and return true if any property is empty. However, I am looking for a way to exclude certain properties from this check. Specifically, I do not want to include generalReal ...

Declare a variable within a function

Consider the scenario where a variable is initialized as follows: Assuming we have: T obj = GetT(); in an aspx page. (GetT() may return a null value). And there is a desire to manage this obj within a function public void HandlingT(T obj){ if(c ...

Web-based Remote attendance system utilizing Smart Card technology in ASP.NET

Currently, I am working on a project focused on developing a SmartCard based Attendance Application. The primary framework being utilized is .NET (ASP.NET / C#). The scenario for this project involves a client who owns three food chain stores labeled as A ...

Is there any distinction between "Windows Authentication" and "Pass-Through Authentication"?

When it comes to app authentication, Windows authentication enables the use of the user's Windows login credentials. But is Windows Authentication the same as Pass-Through Authentication? ...

What is the code to create rainbow-colored buttons in a continuous loop on a webpage using HTML?

My current project is built using the Jango framework. {% for tag in tags %} <div class="btngroup" role="group" aria-label="tags"> <h3><a href="{{ tag.get_absolute_url }}" class="btn btn-primary">{{tag.title}}</a></h3> ...

Tips for effectively passing navigation as props in React Navigation with Expo

How can I correctly pass navigation as props to another component according to the documentation? The navigation prop is automatically provided to each screen component in your app. Additionally, To type check our screens, we need to annotate the naviga ...

When it is first activated, the Ajax .load() function will not function correctly

I recently encountered an issue with a tab system that I implemented using the .load function to load content dynamically. The problem arose because the page containing this tab system was loaded via ajax, causing the initial call to the tab function to di ...

Angular - Async function does not resolve a rejected promise

Currently, my component utilizes an async method for handling file uploads. Here is an example: //component uploadPhotos = async (event: Event) => { const upload = await this.uploadService.uploadPhotos(event, this.files, this.urls); } The UploadSe ...

Tips for loading HTML content before executing any JavaScript code or requesting user input via prompt

I am looking to have the page function in a specific way: The HTML loads, and the first prompt asks the user for input. Once the prompt is submitted, the running total changes and is displayed on the page. The same process happens for the second prompt and ...

The array.slice() method fails to work properly when I try to start it from any index other than 0

I am currently working with an array called $scope.results which contains 8 objects. I have also created a custom simple pagination and a function called selectAll() that I'm trying to get to work together. Please refrain from suggesting the use of b ...