|
As expected, Microsoft's long awaited rewrite of the
original webservice behavior HTC has arrived: http://msdn.microsoft.com/library/default.asp?url=/workshop/author/webservice/using.asp
This new working version weighs in at about 47K (vs the
Beta 1 at about 17K). On first inspection, it looks like the extra weight
is due to the addition of a number of new properties such as
onresult, username, password, portname, and useOptions
with reuseConnection for SSL access to webservices.
The original "NOTE" (quoted following):
Note The current implementation of the WebService behavior requires
that the Web Services being referenced directly by the useService method
reside on the same domain as the Web server that delivers the Web page.
-- is still there; however, I have been able to call remote webservices
with the HTC that are located on another domain than the webserver delivering
the webpage, so "go figure".
Obviously, the first thing I wanted to do is test it
out on an existing webservice that I had already written, so I whipped
up the following page using the onResult (non-callback) method:
<SCRIPT language="JavaScript">
var iCallID = 0;
function init()
{
// Establish the friendly name "StockQuote" for the WebServiceURL
service.useService("https://www.nullskull.com/webservices/StockQuote/Stockquote.asmx?WSDL","StockQuote");
// The following method doesn't specify a callback handler, so onWSresult()
is used
iCallID = service.StockQuote.callService("GetQuote", symbols.value);
}
function onWSresult()
{
// if there is an error, and the call came from the call() in init()
if((event.result.error)&&(iCallID==event.result.id))
{
// Pull the error information from the event.result.errorDetail properties
res.innerText = event.result.errorDetail.code;
res.innerText+="\n"+ event.result.errorDetail.string;
res.innerText+= "\n"+event.result.errorDetail.raw;
// Add code to handle specific error codes here
}
// if there was no error, and the call came from the call() in init()
else if((!event.result.error) && (iCallID == event.result.id))
{
// perform transform and show result
var xmldoc=new ActiveXObject("MSXML2.DOMDocument.3.0");
xmldoc.async=false;
xmldoc.loadXML(event.result.value);
var xsldoc=new ActiveXObject("MSXML2.DOMDocument.3.0");
xsldoc.async=false;
xsldoc.load("./Stock.xsl");
//alert(xsldoc.xml);
res.innerHTML=xmldoc.transformNode(xsldoc);
}
else
{
alert("Something else fired the event!");
}
}
</SCRIPT>
<body >
<div id="service" style="behavior:url(webservice.htc)"
onresult="onWSresult()">
</div>
<input type=text id=symbols
value="YHOO IBM MSFT">Enter Symbols separated by spaces
<input type=button value="Get Quotes" onclick="init();">
<div id=res align="center"><div>
</body>
To my pleasant surprise, it worked - that
is, MOST of the time. Occasionally the browser got stuck and I haven't
figured out why yet. But if you'd like to try my example on the eggheadcafe
StockQuote Service, try
here.
If it doesn't work, or your browser freezes, don't blame
me! I already warned you that it works MOST of the time! You can download
the code for the actual WebService, the Xsl for the transform, the Webservice.HTC
and the TestWebserviceBehavior.htm client page at the link below.
Download
the code that accompanies this article
Peter Bromberg is an independent consultant specializing in distributed .NET solutionsa Senior Programmer
/Analyst at in Orlando and a co-developer of the NullSkull.com
developer website. He can be reached at info@eggheadcafe.com
|