Solved

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

Posted on 2011-03-13
5
488 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
creating a flowchart from an algorithm 5 30
Need an intro to -- .Net SQL Authorization Manager 7 76
Asp.net mvc 5 5 43
Json and asp.net mvc 2 44
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

911 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

19 Experts available now in Live!

Get 1:1 Help Now