Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-03-13
5
Medium Priority
?
517 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

660 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