Solved

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

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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