hello.
the best way to find out what's going on is to use fiddler. it'll show you the response you're getting from the server and by seeing that it's easier to find out the problem.
btw, you should make sure that your web service is annottated with the ScriptServiceAttribute.
Thank you for your response.
But I am still where I started.
Fiddler shows that the error is on the line:
Samples.AspNet.HelloWorldService.HelloWorld(SrchElem.value, OnRequestComplete);
The Path within the ScriptManager is this:
<asp:ServiceReferencepath="~/HelloWorldService.asmx"/>Within the Service "HelloWorldService.asmx" theClass is"Samples.AspNet.HelloWorldService".The namespace is "Samples.AspNet".
The name of the "public class" is "HelloWorldService".
And the name and parameter of the WebMethod is "HelloWorld(String query)"
The following is first the source of the Web Service, followed by the source of the WebPage calling it. Might anyone have an idea what might be causing "Samples" to be undefined?
==========================Service Follows==============================
<%
@.WebServiceLanguage="C#"Class="Samples.AspNet.HelloWorldService" %>using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using Microsoft.Web.Script.Services;
namespace Samples.AspNet
{
[WebService(Namespace =http://tempuri.org/)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class HelloWorldService : 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}", inputString, DateTime.Now);
}
else
{
return "The query string was null or empty";
}
}
}
}
==========================Service Ends==============================
==========================Web Page Begins==========================
<%@. Register Assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="Microsoft.Web.UI" TagPrefix="asp" %>
<%@. Page Language="C#" Title="ASP.NET AJAX Script Walkthrough" %>
<!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 id="Head1" runat="server">
<title="ASP.NET AJAX Script Walkthrough" />
<style type="text/css">
body { font: 11pt Trebuchet MS;
font-color: #000000;
padding-top: 72px;
text-align: center }
.text { font: 8pt Trebuchet MS }
</style>
</head>
<body>
<form id="Form1" runat="server">
<asp:ScriptManager runat="server" ID="scriptManager">
<Services>
<asp:ServiceReference path="~/HelloWorldService.asmx" />
</Services>
</asp:ScriptManager>
<div>
Search for
<input id="SearchKey" type="text" />
<input id="SearchButton" type="button" value="Search" onclick="DoSearch()" />
</div>
</form>
<hr style="width: 300px" />
<div>
<span id="Results"></span>
</div>
<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>
</body>
</html>
Thank you for your response.
But I am still where I started.
Fiddler shows that the error is on the line:
Samples.AspNet.HelloWorldService.HelloWorld(SrchElem.value, OnRequestComplete);
The Path within the ScriptManager is this:
<asp:ServiceReferencepath="~/HelloWorldService.asmx"/>Within the Service "HelloWorldService.asmx" theClass is"Samples.AspNet.HelloWorldService".The namespace is "Samples.AspNet".
The name of the "public class" is "HelloWorldService".
And the name and parameter of the WebMethod is "HelloWorld(String query)"
The following is first the source of the Web Service, followed by the source of the WebPage calling it. Might anyone have an idea what might be causing "Samples" to be undefined?
==========================Service Follows==============================
<%
@.WebServiceLanguage="C#"Class="Samples.AspNet.HelloWorldService" %>using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using Microsoft.Web.Script.Services;
namespace Samples.AspNet
{
[WebService(Namespace =http://tempuri.org/)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class HelloWorldService : 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}", inputString, DateTime.Now);
}
else
{
return "The query string was null or empty";
}
}
}
}
==========================Service Ends==============================
==========================Web Page Begins==========================
<%@. Register Assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="Microsoft.Web.UI" TagPrefix="asp" %>
<%@. Page Language="C#" Title="ASP.NET AJAX Script Walkthrough" %>
<!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 id="Head1" runat="server">
<title="ASP.NET AJAX Script Walkthrough" />
<style type="text/css">
body { font: 11pt Trebuchet MS;
font-color: #000000;
padding-top: 72px;
text-align: center }
.text { font: 8pt Trebuchet MS }
</style>
</head>
<body>
<form id="Form1" runat="server">
<asp:ScriptManager runat="server" ID="scriptManager">
<Services>
<asp:ServiceReference path="~/HelloWorldService.asmx" />
</Services>
</asp:ScriptManager>
<div>
Search for
<input id="SearchKey" type="text" />
<input id="SearchButton" type="button" value="Search" onclick="DoSearch()" />
</div>
</form>
<hr style="width: 300px" />
<div>
<span id="Results"></span>
</div>
<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>
</body>
</html>
Thank you for your response.
But I am still where I started.
Fiddler shows that the error is on the line:
Samples.AspNet.HelloWorldService.HelloWorld(SrchElem.value, OnRequestComplete);
The Path within the ScriptManager is this:
<asp:ServiceReferencepath="~/HelloWorldService.asmx"/>Within the Service "HelloWorldService.asmx" theClass is"Samples.AspNet.HelloWorldService".The namespace is "Samples.AspNet".
The name of the "public class" is "HelloWorldService".
And the name and parameter of the WebMethod is "HelloWorld(String query)"
The following is first the source of the Web Service, followed by the source of the WebPage calling it. Might anyone have an idea what might be causing "Samples" to be undefined?
==========================Service Follows==============================
<%
@.WebServiceLanguage="C#"Class="Samples.AspNet.HelloWorldService" %>using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using Microsoft.Web.Script.Services;
namespace Samples.AspNet
{
[WebService(Namespace =http://tempuri.org/)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class HelloWorldService : 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}", inputString, DateTime.Now);
}
else
{
return "The query string was null or empty";
}
}
}
}
==========================Service Ends==============================
==========================Web Page Begins==========================
<%@. Register Assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="Microsoft.Web.UI" TagPrefix="asp" %>
<%@. Page Language="C#" Title="ASP.NET AJAX Script Walkthrough" %>
<!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 id="Head1" runat="server">
<title="ASP.NET AJAX Script Walkthrough" />
<style type="text/css">
body { font: 11pt Trebuchet MS;
font-color: #000000;
padding-top: 72px;
text-align: center }
.text { font: 8pt Trebuchet MS }
</style>
</head>
<body>
<form id="Form1" runat="server">
<asp:ScriptManager runat="server" ID="scriptManager">
<Services>
<asp:ServiceReference path="~/HelloWorldService.asmx" />
</Services>
</asp:ScriptManager>
<div>
Search for
<input id="SearchKey" type="text" />
<input id="SearchButton" type="button" value="Search" onclick="DoSearch()" />
</div>
</form>
<hr style="width: 300px" />
<div>
<span id="Results"></span>
</div>
<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>
</body>
</html>
hello.
when you load the page on the browser, what else does fiddle show you? i think you'll see a red line with a 500 error regarding the url of your webservice. can you see what's written? there?
Dear Friends:
Thank you for the suggestion. But as I have continued to work through these AJAX examples, I came to another sample which told me that to enable JavaScript Calls to Web Services, you must add or include the following into the web applications Web.Config file:
<
httpHandlers><removeverb="*"path="*.asmx"/>
<addverb="*"path="*.asmx"type="Microsoft.Web.Script.Services.ScriptHandlerFactory"validate="false"/>
</httpHandlers> Once the above reference was added, the above web application function just fine. The problem is now solved.
Sincerely, Dropkick.
No comments:
Post a Comment