Refresh ColdFusion web services

Written on 16 March 2012, 03:44pm

Tagged with: , ,

ColdFusion caches the WSDL. In order to flush this cache, you have the following options:

  1. ColdFusion administrator
  2. Programatically:
    In ColdFusion 8, you have two options:

    1. Cfinvoke’s refreshWSDL attribute:
      <cfinvoke webservice="#wsdl#" method="method"
              returnvariable="rv" refreshWSDL="yes">
              <cfinvokeargument name="arg" value="1"/>
      </cfinvoke>
            
    2. Cfobject’s arguments structure
      <cfscript>
            wsargs = structnew();
            wsargs.refreshwsdl="yes";
            somevar = createobject("webservice",
      "http://[server]/[webserviceurl]",wsargs);
            ...
      </cfscript>

    In ColdFusion 7, however, you can use the following solution:

    <cfset wsAddress = "http://your.web/service/url.cfc?wsdl">
    <!--- CF7 --->
    <cfset createObject("java", "coldfusion.server.ServiceFactory").
    XmlRpcService.refreshWebService(wsAddress) /> 
    

Read more

  1. CF8 Hidden Gem: Refreshing Web Service WSDL and CF proxy/stub with new RefreshWSDL option
  2. CF8 Hidden Gem: New ArgStruct argument for createObject with web services
  3. Flushing a cached web service (see also first comment)
  4. Refreshing Cached ColdFusion Webservices Through the Back Door (ignore the Comic Sans typeface)

29 February ColdFusion bug

Written on 9 March 2012, 10:57pm

Tagged with: , ,

This is just to log a funny bug I encountered a few days ago, on the 29th of February 2012. There was a piece of code that was comparing if a certain date is older than a year or not.
The algorithm to compare the date was creating the ‘one-year-ago date’ by substracting one unit from the current year. Something like:

<cfset aYearAgo = CreateDate(year-1,month,day)>

Obviously, this algorithm was failing on the 29th of February on the leap years (like 2012).
The solution is quite simple: instead of substracting one unit from the year, substract 365 days from the current date, using Coldfusion’s dateAdd function:

<cfset aYearAgo = DateAdd('d', -365, Now())> 
Image: Smashing Magazine’s Desktop Wallpaper Calendar February 2012

Coldfusion dot-notation: using multiple dots

Written on 23 February 2012, 10:25am

Tagged with: ,

A refresher about the ColdFusion structures:

ColdFusion structures consist of key-value pairs. Structures let you build a collection of related variables that are grouped under a single name.

Structure notation
ColdFusion supports three types of notation for referencing structure contents. The notation that you use depends on your requirements.

1. Object.property
You can refer to a property, prop, of an object, obj, as obj.prop. This notation, also called dot notation, is useful for simple assignments, as in this example:
depts.John="Sales"
2. Associative arrays
3. Structure
Adobe Livedocs

What is interesting about the dot-notation, is that using multiple dots in referencing the object property – is allowed.
The following code executes correctly in ColdFusion 8 and outputs ‘Foo’:

<cfset myStruct = StructNew()>
<cfset myStruct.a = '1'>
<cfset myStruct.b = '2'>
<cfset myStruct.c = '3'>

<CFIF #myStruct..a# EQ 1 
	AND #myStruct.....b# EQ 2
	AND #myStruct..........c# EQ 3
>
	Foo
</CFIF>