Some Notes on HTC files

I have only just come across htc files over the last couple of days (Hyper Text Components). These are essentially controls that extend the DOM for a page. The controls must be referenced in container – which has a style attribute set to e.g. “BEHAVIOR:url(”.

I used a htc file in calling a webservice via JavaScript. Note that in the example I looked into, the file was a standard Microsoft script. The htc file for webservice calls seems to be based on the Microsoft.XMLHTTP ActiveX object.

Note that general, two functions need to be used when using the ht component – 1. to start the call to the webservice / instantiate the htc stuff and 2. a callback function that processes the returned information.

The reason for looking into htc files is that they seemed to correctly pass credentials through to the webservice (there were perms problems with ntlm auth when trying to call the webservice using simpler ajax stuff – as credentials seemed to be passed through as plain text).

Note that I believe that these only work in IE >5.

function DoWebServiceCall(id)
    var serviceReturn;
    //Set up the service call and set to async.
    document.all("divWS").useService("http://localhost/webservice.asmx?WSDL", "WebServiceMethodName");
    document.all("divWS").WebServiceMethodName.async = false;
    serviceReturn = document.all("divWS").WebServiceMethodName.callService(WebServiceCallback,"WebServiceMethodName", id);
function WebServiceCallback(result)
        var xfaultcode   = result.errorDetail.code;
        var xfaultstring = result.errorDetail.string;
        var xfaultsoap   = result.errorDetail.raw;
        alert("ERROR:" + " c=" + xfaultcode + " s=" + xfaultstring + " soap=" + xfaultsoap);
        document.getElementById("resultDiv").innerHTML = result.value;
<div id="resultDiv">
  Results will be shown in here
<div id="divWS" style="BEHAVIOR: url(/_layouts/1033/"></div>

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>