19 August 2008

Cold Fusion reload web service

ColdFusion does a very enthusiastic job of caching web services, which if you're still developing or making a few changes can be frustrating. I've found this code to be VERY useful to reload a web service cached by cfadmin.


<cfobject type="JAVA"
action="Create"
name="factory"
class="coldfusion.server.ServiceFactory">



<cfset RpcService = factory.XmlRpcService />



<cfset RpcService.refreshWebService("http://myURL/webservices/mycfc.cfc?WSDL")>

javascript web service

OK so AJAX / JS...whateves right?

This little bit of code allows you to call a web service from JavaScript. I have found many articles and ways of doing this on the interweb and non of them seem to work. This one works with CF web services.

The interesting thing i found is you don't need to pass parameters using the XMLHttpRequest method, to call a specific function just append &method= to the end of the wsdl string.


function ajaxFunction()

{

var xmlHttp;

try

{

// Firefox, Opera 8.0+, Safari

xmlHttp=new XMLHttpRequest();

}

catch (e)

{

// Internet Explorer

try

{

xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

}

catch (e)

{

try

{

xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

}

catch (e)

{

alert("Your browser does not support AJAX!");

return false;

}

}

}

xmlHttp.onreadystatechange=function()

{

if(xmlHttp.readyState==4)

{

document.getElementById("myDivResponse").innerHTML = xmlHttp.responseText;

}

}

xmlHttp.open("GET","http://myurl/webserrvices/mycfc.cfc?WSDL&method=getSomething",true);

xmlHttp.send(null);

}