We have an intranet site (several hundred pages) that we're converting to a standard DWT (Dynamic Web Template). To help facilitate this, we're looking for a way to dynamically populate some of the page content from various databases. I've been able to accomplish this within an ASP.Net application, but that isn't an option for use with the several hundred static .htm files we also need to convert.
So here's what I'm looking at:
anypage.htm
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Testing HTML Access to Web Service</title>
<script src="http://someserver/scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="http://someserver/webservice.asmx/js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
function GetTime() {
WebService.GetTime(onSuccess, onFailure);
}
function onSuccess(result) {
$('Time').innerHTML = result;
}
function onFailure(result) {
alert(result.get_message());
}
</script>
</head>
<body>
<h1>Testing HTML consumption of web services</h1>
<form id="frm">
<input id="Button1" type="button" value="Get Time" onclick="GetTime()" /><br />
<div id="Time"></div><br />
</form>
</body>
</html>
WebService.asmx
using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
[WebService(Namespace = "WebService")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
public WebService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string GetTime() {
return DateTime.Now.ToString();
}
}
Doing some debugging and walking through the various steps, everything SEEMS to be working as it should...however, result keeps returning a 404 error (if you look at the get_status() portion of the result object) with the message that "The server method 'GetTime' failed".
I'm presently running the .htm file from my development box (localhost) and pointing to the development server (someserver). I was lead to believe that using the MicrosoftAjax.js approach (above) allowed for the cross domain scripting issues? Is this even that? Found oodles of comments / how-to regarding the .htc component method to do the same thing, but that's really not an option we can use in this environment. Thoughts? Suggestions? Sanity?? **grin**