I had the same issue, but found that the WebService.asmx class required a new attribute. Once I added it, all worked:
[Microsoft.Web.Script.Services.ScriptService()] public class WebService : System.Web.Services.WebService
{
[WebMethod]
public void HelloWorld()
{
string test= "Hello World"; //added a breakpoint here to catch the call
}
}
I'm also having the same problem. It would seem that someone from Microsoft would explain the bugs they create. If anyone could figure out how to fix this problem, please let us know.
In your case Kryptonic, the first thing to do would be to add the [Microsoft.Web.Script.Services.ScriptService()] to the web service.
Another thing that I noticed is that your javascript function doesn't have a callback function. You need to add something like this:
function test() {
WebService.HelloWorld(OnRequestComplete);
}
// Event handler that processes the
// Web service return value.
function OnRequestComplete(result)
{
alert(result);
}
Make sure that you rebuild your solution, in order to update the generated proxy file for your web service.
You can check the proxy file, typing /js after your service address (e.g. http://yourapppath/yourservicename.asmx/js)
I also would use another name for the web service just to avoid collision with the WebService attribute.
And the last thing (I guess)... I would change the way you include your js file. The ScriptReference control is meant to be used differently.
So I would place the script code inside the page or would add trough a
<script type="text/javascript"
src="WebService.js"
/>
Hope that helps,
Maíra
This posting is provided "AS IS" with no warranties, and confers no rights.
I came across this page lookig for the web service undefined error problem. I eventually found the problem which was namespace related. Ive detailed it in my blog:
The problem lies when you are using a web application project. Since web application projects use namespaces you need to add it before your call to the service. Also I needed to add
using System.Web.Script.Services; and [ScriptService] to my asmx code behind. Below I will give an example of how to get this working.
Create your webservice. I added mine in a sub directory of my site named Services. So when looking into the code behind of the webservice you will see something like:
namespace MyNamespace.Services you want to remember this. Next thing is to add:
using System.Web.Script.Services; with the rest of the includes and also add the line:
[ScriptService] just before the public class MyService : System.Web.Services.WebService
Next is to go to the aspx page and create the proxy.
Notice the “MyNamespace.Services.” before the name of the webservice. This is important to add when using a web application project, it is not need when making a regular
web site because a web site does not use namespaces. So there you go, you should now be able to get things up and running.
I am also using a Web Application prject and I have added a namespace to the .asmx class. However my code is calling the js page but gets an error on the line where i make the call to the WebService. I have been circling this issue for 2 days, any help is
greatly appreciated.
Kryptonic
Member
55 Points
11 Posts
Microsoft JScript runtime error: 'WebService' is undefined ??
Nov 06, 2006 04:01 PM|LINK
Hey all, ive been using CTP Atlas for a while, and im tying to upgrade some of my code to beta 1..
but im getting: Microsoft JScript runtime error: 'WebService' is undefined
New project > Ajax Enabled Website
WebService.asmx.js
function test()
{
WebService.HelloWorld();
}
WebService.asmx
[WebMethod]
public void HelloWorld()
{
string test= "Hello World"; //added a breakpoint here to catch the call
}
Default.aspx
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="WebService.asmx" />
</Services>
<Scripts>
<asp:ScriptReference Path="WebService.asmx.js" />
</Scripts>
</asp:ScriptManager>
<div>
<button type=button onclick="test();" >hahaha</button>
</div>
thats the basics ive done, now it should work..... but it doesnt :-(
Any idea waht im doing wrong?? Cheers guys!
skb
Member
35 Points
19 Posts
Re: Microsoft JScript runtime error: 'WebService' is undefined ??
Nov 06, 2006 10:17 PM|LINK
I had the same issue, but found that the WebService.asmx class required a new attribute. Once I added it, all worked:
[Microsoft.Web.Script.Services.ScriptService()]
public class WebService : System.Web.Services.WebService
{
[WebMethod]
public void HelloWorld()
{
string test= "Hello World"; //added a breakpoint here to catch the call
}
}
Hope this helps.
steven
kali.mist
Member
124 Points
69 Posts
Re: Microsoft JScript runtime error: 'WebService' is undefined ??
Nov 30, 2006 09:11 AM|LINK
Folks,
I am having the same problem. Adding the scriptservice attribute does not help.
//Web Service
Imports
System.WebImports
System.Web.ServicesImports
System.Web.Services.ProtocolsImports Microsoft.Web.Script.Services
<WebService(Namespace:="http://tempuri.org/")> _
<ScriptService()> _
Public
Class CarService Inherits System.Web.Services.WebService<WebMethod()> _
Public Function getcarvalue(ByVal strCarMake As String, ByVal strCarModel As String, ByVal strCaryear As String) As Integer ........ End FunctionEnd
Class//Client Code
<
script language="javascript" type="text/javascript">// <!CDATA[
function
Button1_onclick() {requestValue = CarService.getcarvalue(
form1.txtMake.value,
form1.txtModel.value,
form1.txtYear.value,
OnComplete,
OnTimeOut);
return false;}
function
OnComplete(result){
alert(
"Car is worth: $" + result);}
function
OnTimeOut(result){
alert(
"Timeout: " + result);}
// ]]>
</
script></
head><
body> <form id="form1" runat="server"> <div>
<asp:ScriptManager ID="ScriptManager1" runat="server"> <Services> <asp:ServiceReference Path="CarService.asmx"/> </Services> </asp:ScriptManager>Make:
<input id="txtMake" type="text" /> <br />Model:
<input id="txtModel" type="text" /><br />Year:
<input id="txtYear" type="text" /> <br /> <input id="Button1" type="button" value="Get Value" onclick="return Button1_onclick()" /></div> </form></
body></
html>TheBigOnion
Member
80 Points
17 Posts
Re: Microsoft JScript runtime error: 'WebService' is undefined ??
Nov 30, 2006 08:20 PM|LINK
I'm also having the same problem. It would seem that someone from Microsoft would explain the bugs they create. If anyone could figure out how to fix this problem, please let us know.
Thanks,
Michael.
maira.wenzel
Member
511 Points
111 Posts
Microsoft
Re: Microsoft JScript runtime error: 'WebService' is undefined ??
Nov 30, 2006 09:59 PM|LINK
Hi kali.mist,
I tested your code against Beta 2 and it worked just fine.
Maíra
kali.mist
Member
124 Points
69 Posts
Re: Microsoft JScript runtime error: 'WebService' is undefined ??
Dec 01, 2006 03:30 PM|LINK
Thanks Maira,
I rebuilt everything from scratch and it worked!! Ive compared the two web sites but could not find the problem that caused the first to fail.
Cheers
Mick
maira.wenzel
Member
511 Points
111 Posts
Microsoft
Re: Microsoft JScript runtime error: 'WebService' is undefined ??
Dec 01, 2006 09:19 PM|LINK
In your case Kryptonic, the first thing to do would be to add the [Microsoft.Web.Script.Services.ScriptService()] to the web service.
Another thing that I noticed is that your javascript function doesn't have a callback function. You need to add something like this:
function test() {
WebService.HelloWorld(OnRequestComplete);
}
// Event handler that processes the
// Web service return value.
function OnRequestComplete(result)
{
alert(result);
}
Make sure that you rebuild your solution, in order to update the generated proxy file for your web service.
You can check the proxy file, typing /js after your service address (e.g. http://yourapppath/yourservicename.asmx/js)
I also would use another name for the web service just to avoid collision with the WebService attribute.
And the last thing (I guess)... I would change the way you include your js file. The ScriptReference control is meant to be used differently.
So I would place the script code inside the page or would add trough a <script type="text/javascript" src="WebService.js" />
Hope that helps,
Maíra
omen
Member
6 Points
5 Posts
Re: Microsoft JScript runtime error: 'WebService' is undefined ??
Jul 17, 2007 12:10 PM|LINK
Hi
I came across this page lookig for the web service undefined error problem. I eventually found the problem which was namespace related. Ive detailed it in my blog:
http://omensblog.blogspot.com/2007/07/aspnet-ajax-web-service-calls-from.html
cheers
Damian
Lankern
Member
4 Points
3 Posts
Re: Microsoft JScript runtime error: 'WebService' is undefined ??
Aug 10, 2007 05:05 PM|LINK
The problem lies when you are using a web application project. Since web application projects use namespaces you need to add it before your call to the service. Also I needed to add using System.Web.Script.Services; and [ScriptService] to my asmx code behind. Below I will give an example of how to get this working.
Create your webservice. I added mine in a sub directory of my site named Services. So when looking into the code behind of the webservice you will see something like: namespace MyNamespace.Services you want to remember this. Next thing is to add: using System.Web.Script.Services; with the rest of the includes and also add the line: [ScriptService] just before the public class MyService : System.Web.Services.WebService
Next is to go to the aspx page and create the proxy.
<div class="codecolorer-container javascript"><div class="codecolorer" style="font-family: monospace;"><script language="javascript" type="text/javascript"></div><div class="codecolorer" style="font-family: monospace;"> </div><div class="codecolorer" style="font-family: monospace;"> function ButtonClick(){ MyNamespace.Services.MyService.MyFunction(OnComplete) }
</div><div class="codecolorer" style="font-family: monospace;"> </div><div class="codecolorer" style="font-family: monospace;"> function OnComplete(results)
{ alert (results) }</div><div class="codecolorer" style="font-family: monospace;"> </div><div class="codecolorer" style="font-family: monospace;"></script> </div></div>
andyaiyer
Member
45 Points
12 Posts
Re: Microsoft JScript runtime error: 'WebService' is undefined ??
Oct 17, 2007 04:55 PM|LINK
Hi Lankern,
I am also using a Web Application prject and I have added a namespace to the .asmx class. However my code is calling the js page but gets an error on the line where i make the call to the WebService. I have been circling this issue for 2 days, any help is greatly appreciated.
<asp:ScriptManager ID="ScriptManager1" runat="server"> <Services> <asp:ServiceReference Path="WebService.asmx" /> </Services> <Scripts> <asp:ScriptReference Path="WebService.js" /> </Scripts> </asp:ScriptManager>