ColdFusion Muse

Refreshing a webservice in the Cache

Mark Kruger July 13, 2005 11:29 AM Coldfusion MX 7, Coldfusion Tips and Techniques Comments (7)

Web services are great - but they are not a magic bullet. You have to become familiar will all their little quirks to use them effectively. This is a nice tip I picked up on the email list for BACFUG (I love the retro logo). Sometimes you might have a CFC that you are calling as a webservice like this:

<cfscript>
// service wsdl file
sdl   =   'http:/' & '/mydomain.com/WS/myservice.cfc?wsdl';
// create object
sv = CreateObject('webservice', sdl);
</cfscript>
If you make a change to a method in the CFC (add or change an argument - or a type), and you refresh your page that uses the web service, you may not see the change. That is because the CF Server creates a "stub" (a proxy class) from your WSDL and puts it in the cache. It does not automatically know that the file has changed. You can refresh the cache from the CF administrator, but you may not always have access to it (if you are on a shared server). In fact, the CF Admin method doesn't always work for some reason. Not to worry, Tarik Ahmed (Cflex.net) offers this programmatic solution.
<cfscript>
// service wsdl file
sdl   =   'http:/' & '/mydomain.com/WS/myservice.cfc?wsdl';
// create object
factory = CreateObject('JAVA', "coldfusion.server.ServiceFactory");
// reference to the XmlRpcService
RpcService = factory.XmlRpcService;
// refresh the object in question
RpcService.refreshWebService(sdl);
</cfscript>

  • Share:

7 Comments


Leave this field empty

Write a comment

If you subscribe, any new posts to this thread will be sent to your email address.

  • Dave Shuck's Gravatar
    Posted By
    Dave Shuck | 7/13/05 10:26 AM
    Unbelievable timing! I had just made a post on my blog a few hours ago about this being a negative to authoring web services in ColdFusion and that I hadn't found any documentation on a workaround.

    Thanks!
  • Jason Nussbaum's Gravatar
    Posted By
    Jason Nussbaum | 7/13/05 10:48 AM
    This also explains why the Web Services and Remoting Services panels in Flash don't update with changes when hitting refresh. I wonder if there's some way to fix that...
  • mkruger's Gravatar
    Posted By
    mkruger | 7/13/05 11:13 AM
    Glad I could help. Sometimes I just stumble onto something and say "wow... I didn't know that." It usually ends up in a blog (ha).
  • Carl Steinhilber's Gravatar
    Posted By
    Carl Steinhilber | 11/3/05 12:09 PM
    We're still having issues with some of our web services since upgrading to MX7.

    On one particular server, the WS (which ran fine under MX6.1) is returning the dreaded "Could not generate stub objects for web service invocation".

    But when I pull up the WSDL in the browser, there are no errors... and, like I said, it was operating fine under MX6. And, in fact, the same CFC runs fine as a webservice on another MX7 box.

    I've tried refreshing the WS using factory code similar to above... and I've tried completely deleting the WS from cache (via factory or cfadmin). Still returns the error.

    Why would the WSDL come up fine, but MX7 still has a problem with registering/caching the webservice? I'm thinking it's a directory permissions issue... but everything appears to be set up exactly the same as it was under MX6, and the same as the other MX7 box that's working.
  • dan's Gravatar
    Posted By
    dan | 10/4/06 9:23 AM
    Mark
    Do you know if the javadocs are available anywhere for the ServiceFactory package?
  • bilgisayar's Gravatar
    Posted By
    bilgisayar | 7/31/07 8:35 AM
    thank you
  • Peter's Gravatar
    Posted By
    Peter | 8/23/09 12:54 AM
    Dude, you just saved my behind! Thanks.