Solved

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

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

726 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