Solved

Help: Issue with JavaScript Calling WebService from ASP.NET 4

Posted on 2011-03-13
5
480 Views
Last Modified: 2012-05-11
I seen to have run into an error that I have found documented on the web from a few years ago but the suggestions don't help me. My environment is Win7x64/VS2010 / ASP.NET 4 / VB.NET and a target cpu of x86.

I have tried various websites to get a working example but they all result in the same error message "Microsoft JScript runtime error: 'xxxxxxxxx' is undefined" . I

Below is some code extracts from a MS site that has JavaScript calling a WebService which I'd appreciate some help with getting to work.

HTML and JS code...

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
<script language="javascript" type="text/javascript">
    function Button1_onclick() 
            {
                ret = SimpleService.SayHello(document.getElementById('Text1').value, OnComplete, OnTimeOut, OnError);
                return(true);
            }

function OnComplete(args) {
document.getElementById('Text2').innerText = args;
            }
            function OnTimeOut(args) {
            alert("Service call timed out.");
            }

function OnError(args) {
alert("Error calling service method.");
}
</script>
</head>
<body style="text-align: center">
    <form id="form1" runat="server">
    <div>
        
        <asp:ScriptManager ID="ScriptManager1" runat="server">
            <Services>
                <asp:ServiceReference Path="~/SimpleService.asmx" />
            </Services>
        </asp:ScriptManager>

        Joes Simple App<br />
        <br />
        <input id="Text1" type="text" /><br />
        <br />
        <input id="Button1" style="width: 193px" type="button" value="button" language="javascript" onclick="return Button1_onclick()" /><br />
        <br />
        <input id="Text2" style="width: 495px" type="text" /></div>
    </form>
</body>
</html>

Open in new window


The WebService....

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

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

    <WebMethod()> _
    Public Function SayHello(ByVal inStr As String) As String
        Return "Hello : " + inStr + "; Thanks for visiting."
    End Function

End Class

Open in new window



Thanks for any help.

Mark
0
Comment
Question by:RibTime
  • 4
5 Comments
 
LVL 8

Expert Comment

by:johny_bravo1
ID: 35122160
Just a guess,
if you are using any URL rewriting mechanism,please exclude the web service from that.
0
 

Author Comment

by:RibTime
ID: 35126874
None of that going on!
0
 

Accepted Solution

by:
RibTime earned 0 total points
ID: 35128242
Ok, I have the answer.

1) From the "Solution Explorer" I right-clicked on the "asmx" file and select "View Markup"

2) Make a note of the class value. In my case the line read ...
<%@ WebService Language="vb" CodeBehind="SimpleService.asmx.vb" Class="modal3.SimpleService" %>

Open in new window


3) I then amended line 11 of my html/js file from
ret = SimpleService.SayHello(document.getElementById('Text1').value, OnComplete, OnTimeOut, OnError);
                return(true);

Open in new window

to
ret = [b]modal3.[/b]SimpleService.SayHello(document.getElementById('Text1').value, OnComplete, OnTimeOut, OnError);
                return(true);

Open in new window


Done!!
0
 

Author Comment

by:RibTime
ID: 35128261
Formatting seems a bit odd!

In my code above the line with "modal3." should read "modal3", i.e. no bold HTML tags
0
 

Author Closing Comment

by:RibTime
ID: 35170779
Well done me!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now