I could not attend the PDC, so i was very happy to see the hands on labs beeing published and started working with the labs. But i'm getting javascript errors in lab 1. The message says that "Samples" is not
defined. The script is shown below:
<
script type="text/javascript"
src="HelloWorldService.asmx/js"></script>
<script
type="text/javascript">
function DoSearch()
{
var SrchElem = document.getElementById("SearchKey");
That's right. I created the pages as described in the lab documentation. I copied sections from the documentation into the pages I added with VS (I did not want to enter all the code again, to lazy).
But still it does not work. I have doublechecked (even triplechecked) it.
Henk, could you post a copy of your code you are using for the HelloWorldService.asmx file? I believe you that you followed the lab steps, but somehow it sounds like the namespace reference may be off. The top section of your web service code, up to the point
of the namespace declaration, should look EXACTLY like this when you are using C#:
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
namespace Samples.AspNet {
If you have even a single letter with the wrong case or something in the namespace name, it would fail. As a quick fix, rather than hunting through your code to find potential issues, you might consider wiping your code in your web service file, and doing a
copy/paste of the web service code from the lab (a complete listing of the HelloWorldService.asmx file is found at the very end of Lab 1, Exercise 2, Task 3.
This posting is provided "AS IS" with no warranties, and confers no rights.
Someone reported this same problem last night at the hands on labs at the PDC. They had inadvertantly left out the namespace on the class name in the webservice directive in the ASMX. They had written:
Once they added the namespace to the class name (so it was a fully qualified class name) the error message went away and everything worked beautifully. Hope this helps.
System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
namespace
Samples.AspNet
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo =
WsiProfiles.BasicProfile1_1)]
public
class HelloWordService : System.Web.Services.WebService
{
[WebMethod]
public
string HelloWorld(String query)
{
string inputString = Server.HtmlEncode(query);
if (!String.IsNullOrEmpty(inputString))
{
return
String.Format("Hello, you queried for {0}. The current"
+ " time is {1}", query,
DateTime.Now);
}
else
{
return "The query string was null or empty";
}
}
}
}
I don't see anything wrong. In fact, I copied it from the lab documentation into my asmx file and i still got the problem.
Be sure that you've not accidentally indicated that you want your web service (ASMX) to use a code behind file (ASMX.CS or ASMX.VB). You may have forgotten to uncheck the checkbox in VS that indicates whether or not to automatically create the code behind
file. If you have a code behind for your web service it may be in conflict with what you put into the ASMX itself in your sample case.
I see your issue: you have a typo in the class name. You have "HelloWordService", and it should be "HelloWorldService". You're missing the "l". I took your code, pasted it into my solution, fixed the typo, and it runs perfectly. I also double-checked the
doc from where you would have gotten the code, and I do not notice a typo in the original doc, so somehow that typo snuck in there and tripped you up.
Hope that helps.
--Tim
This posting is provided "AS IS" with no warranties, and confers no rights.
H. Feijt
Member
143 Points
43 Posts
Problem with Hands On Lab
Sep 14, 2005 12:00 PM|LINK
<
script type="text/javascript" src="HelloWorldService.asmx/js"></script> <script type="text/javascript"> function DoSearch(){
var SrchElem = document.getElementById("SearchKey");Samples.AspNet.HelloWorldService.HelloWorld(SrchElem.value, OnRequestComplete);
}
function OnRequestComplete(result){
var RsltElem = document.getElementById("Results");RsltElem.innerHTML = result;
}
</script>I think i did everything according to the descriptions in the lab doc.
Anyone a suggestion,
Thanks,
Henk Feijt
Wallym
Contributor
2119 Points
363 Posts
ASPInsiders
MVP
Re: Problem with Hands On Lab
Sep 14, 2005 01:57 PM|LINK
Wally
H. Feijt
Member
143 Points
43 Posts
Betreft: Re: Problem with Hands On Lab
Sep 14, 2005 04:02 PM|LINK
I'm still puzzled.
Henk
leelaram
Member
645 Points
129 Posts
Re: Betreft: Re: Problem with Hands On Lab
Sep 14, 2005 04:57 PM|LINK
timlt
Member
88 Points
21 Posts
Microsoft
Re: Betreft: Re: Problem with Hands On Lab
Sep 14, 2005 04:58 PM|LINK
<%@ WebService Language="C#" Class="Samples.AspNet.HelloWorldService" %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
namespace Samples.AspNet {
If you have even a single letter with the wrong case or something in the namespace name, it would fail. As a quick fix, rather than hunting through your code to find potential issues, you might consider wiping your code in your web service file, and doing a copy/paste of the web service code from the lab (a complete listing of the HelloWorldService.asmx file is found at the very end of Lab 1, Exercise 2, Task 3.
leelaram
Member
645 Points
129 Posts
Re: Betreft: Re: Problem with Hands On Lab
Sep 14, 2005 05:39 PM|LINK
dont know what exactly I changed, but now it is working
Russ Helfand
Contributor
3304 Points
744 Posts
Re: Problem with Hands On Lab
Sep 14, 2005 06:42 PM|LINK
Someone reported this same problem last night at the hands on labs at the PDC. They had inadvertantly left out the namespace on the class name in the webservice directive in the ASMX. They had written:
<%@ WebService Language="C#" Class="HelloWorldService" %>
It should have been:
<%@ WebService Language="C#" Class="Samples.AspNet.HelloWorldService" %>
Once they added the namespace to the class name (so it was a fully qualified class name) the error message went away and everything worked beautifully. Hope this helps.
-Russ-
Groovybits.com
H. Feijt
Member
143 Points
43 Posts
Betreft: Re: Betreft: Re: Problem with Hands On Lab
Sep 14, 2005 09:36 PM|LINK
Below a copy of my asmx file
<%@ WebService Language="C#" Class="Samples.AspNet.HelloWorldService" %>
using
System;using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
namespace
Samples.AspNet{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class HelloWordService : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld(String query)
{
string inputString = Server.HtmlEncode(query);
if (!String.IsNullOrEmpty(inputString))
{
return String.Format("Hello, you queried for {0}. The current"
+ " time is {1}", query, DateTime.Now);
}
else
{
return "The query string was null or empty";
}
}
}
}
I don't see anything wrong. In fact, I copied it from the lab documentation into my asmx file and i still got the problem.
Henk
Russ Helfand
Contributor
3304 Points
744 Posts
Re: Betreft: Re: Betreft: Re: Problem with Hands On Lab
Sep 14, 2005 09:49 PM|LINK
-Russ-
Groovybits.com
timlt
Member
88 Points
21 Posts
Microsoft
Re: Betreft: Re: Betreft: Re: Problem with Hands On Lab
Sep 14, 2005 09:57 PM|LINK
Hope that helps.
--Tim