"Exploring the World of ASP.NET VB: A Beginner's Guide to

Attempting to call a web service using JS from an ASP.NET website (VB) client side. Although familiar with web services, setting one up is new territory for me. Looking to implement async updates and queries. Any assistance, examples, or best practices would be greatly appreciated. Unfortunately, unable to post images...

Seem to be encountering issues related to Namespaces and the correct way of calling methods from client events. Could it possibly be something in the webconfig?

Progress so far:
Started by creating a new ASP website in Visual Studio (website1). Added a new .asmx file named WebService.asmx. Uncommented System.Web.Script.Services.ScriptService(). Created a service reference using the wizard (ServiceReference1). On default.aspx, added the script manager. Created a button onclick and function. Upon running, encountered an error in the JavaScript.

The method I'm trying to use to call the service resembles what I've done in the past on a different system. Will this approach work?:

    function test() {
        ServiceReference1.WebService.HelloWorld();            
    }
<input type="button" onclick="test()"/>

Noticed that in the WebService.asmx there is no Namespace specified for that particular test. Should there be one?:

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebService
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function HelloWorld() As String
        Return "Hello World"
    End Function

End Class

The app_reference imports successfully and the webservice runs fine on its own. Additionally, here is my webconfig:

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
    <system.web>
      <compilation debug="true" strict="false" explicit="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" />
    </system.web>

    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="WebServiceSoap" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:55800/WebService.asmx" binding="basicHttpBinding"
                bindingConfiguration="WebServiceSoap" contract="ServiceReference1.WebServiceSoap"
                name="WebServiceSoap" />
        </client>
    </system.serviceModel>
</configuration>

When the JS fires, it breaks on the webservice line displaying this message:

Error at line 13, column 13 in http://localhost:55800/Default.aspx

JavaScript runtime error: 'ServiceReference1' is undefined

Any suggestions or advice would be greatly appreciated.

Answer №1

To retrieve the desired data, simply use the following code: {WebServiceClass.Method}.

Execute the method WebService.HelloWorld()

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

Tips for adding a "return" button to a page loaded with AJAX

While working with jQuery in prototype to load pages using Ajax, I've come across a feature on big sites like Facebook and Twitter that I'd like to implement: a 'back' button that takes the user back to the previous page when clicked. S ...

Step-by-step guide on utilizing the command prompt to send a file for printing on a network-connected

Does anyone know the steps to print a file using the command prompt on a network shared printer? Kind regards, Vijay. ...

Platform Independent Data Storage Solution

Looking to create a Cross-browser compatible Web Application using HTML, JS, and CSS. In need of a robust database storage solution that can be queried on the client side using JS. While Web SQL/SQLite seems like a good option, it lacks support in IE. Does ...

Uploading base64 arrays from AngularJS to a Node.js server: Allowing Access-Control-Origin

My current challenge involves sending an array of base64 strings from my Client Side (AngularJs) to my NodeJs Server. However, I've encountered a peculiar situation. When I attempt to send an object containing the base64 data along with other properti ...

Issue with Angular Script not functioning upon reopening the page

I recently completed my first website, which can be found at Despite my efforts, I've encountered an issue that has me stumped. When you navigate to the certificate page, you should be able to input your name onto the certificate. However, if you sw ...

Angular: Defining variables using let and var

When working with TypeScript and JavaScript, we typically use either let or var to declare a variable. However, in Angular components, we do not use them even though Angular itself uses TypeScript. For instance, export class ProductComponent implements OnI ...

Retrieve the file from the FTP server only if it is not already included in the specified list of local files

I'm facing a challenge with my FTP server - I need to download all the files that are not already in my local directory. I attempted using a For Next loop, but I'm struggling to figure it out. When trying to compare the online and local files by ...

Ways to turn off hover highlighting

Is there a way to disable the highlighting effect of the <select> element in HTML? When you hover over items in the dropdown list, a blue color strip moves with your mouse. I need to find a way to get rid of this effect. Here is an example of the c ...

Error: An issue occurred in the driver.execute_script function causing a JavascriptException. The error message indicates

When attempting to run some JavaScript code on the Chrome driver, I encountered a JavascriptException. Despite my confidence in the correctness of the JS code, the following error message was displayed: raise exception_class(message, screen, stacktrace) s ...

Ways to restart character count to zero if textarea is blank using jQuery

Can someone assist me with resetting the character count to zero when the textarea field is empty in jQuery? Currently, I have implemented code that successfully adds the character count as shown below; $(document).ready(function() { $('#content& ...

Utilizing Electron to save editable user data in a .txt file

I am making an electron app that converts data from .txt files to Javascript arrays. This data is stored inside a folder called faces in the main directory. I also have a button in my app which, when clicked opens file explorer at the faces folder so the u ...

Is there a way to show the Username across multiple login pages without using PHP?

Is there a way to dynamically display the username on the Homepage by extracting it from the URL? <div id="login"> <form method="post" action=""> <h2>Login</h2> <p> <label for="username"&g ...

The hierarchical structure in the DOM that mirrors an HTML table

While working on code to navigate the DOM for a table, I encountered an unexpected surprise. The DOM (specifically in FF) did not align with my initial expectations. Upon investigation, it appears that FF has automatically inserted a tbody along with sever ...

Building a Loading Bar with Two Images Using JavaScript and CSS

I am currently experimenting with creating a progress bar using two images: one in greyscale and the other colored. My goal is to place these two divs next to each other and then adjust their x-position and width dynamically. However, I'm having troub ...

A TypeError is thrown when attempting to use window[functionName] as a function

I came across this page discussing how to call a function from a string. The page suggests using window[functionName](params) for better performance, and provides an example: var strFun = "someFunction"; var strParam = "this is the parameter"; //Creating ...

The basics of increasing a counter in Asp.net Core

Concerning my controller, I aim to track the number of unsuccessful login attempts. else { // Increase counter by 1 // verify if counter == 3 // block user logonAttempt++; if (logonAttempt >= MAX_LOGON_ATTEMPT) { ...

nested dropdowns in Bootstrap 4

I'm currently working on a nested dropdown menu feature. Although I have successfully implemented the functionality to display the next level, I am facing an issue where it does not close upon clicking. Check out my code here! Here is the JavaScript ...

The issue of sluggishness in Material-UI when expanding the menu is causing delays

Watch Video Having trouble with the behavior of the Menu opening and closing similar to this example. The text seems slow to change position. Any ideas why? This is the devDependencies configuration I am using in webpack. "devDependencies": { ...

Issues with jQuery function arising post-update to newer jQuery version

Recently, I encountered an issue with a function that used to work perfectly fine with jQuery 1.8.3. However, when I upgraded to jQuery 1.10.x or above, the function stopped working. <script type="text/javascript"> $.ajaxSetup({cache: false}); ...

What is the best way to apply a class to a button in Angular when clicking on

Creating a simple directive with two buttons. Able to detect click events on the buttons, but now looking to add a custom class upon clicking. There is a predefined class: .red { background-color: red; } The goal is to dynamically apply this class whe ...