Thursday, September 07, 2006

ColdFusion and Netsuite, a cautionary tale

This post is about Netsuite's web service, but perhaps you've run into similar issues trying to use other web services in ColdFusion. For several weeks, I have been working on a project to integrate a ColdFusion-based system with Netsuite through Netsuite's web service. Netsuite's documentation for the web service is somewhat spotty, but I now realize it was not as entirely inaccurate as I had thought. Here is a somewhat simplified breakdown of the issue.

-When first creating an instance of a given web service using CreateObject("webservice", http://url.of.wsdl), ColdFusion generates stub class files using Apache Axis' wsdl2java. However, I found that not all of the java class files I needed were being compiled. For example, a class file was never generated for CustomerAddressbookList or SearchMultiSelectField. I would try wiping the stubs directory, restarting the ColdFusion service, and running the code to create the web service object again with the exact same results. At first, I compensated by using javac to compile the missing class files myself, however other issues popped up such as...

-Calls to several methods in certain classes like Customer and CustomerSearchBasic would complain about the datatypes of objects being passed to them. For example, according to the source code in and Netsuite's own sample code, the setInternalId method in CustomerSearchBasic expected an object of type SearchMultiSelectField. However, running Ben Nadel's useful function to return all of the exposed methods and expected datatypes for a given class showed that CustomerSearchBasic's setInternalId method was actually expecting a RecordRef object. See a more detailed example here.

-Further adding to the confusion, if there are references to SearchMultiSelectField in CustomerSearchBasic, and a class file for SearchMultiSelectField was never compiled, how on earth is CustomerSearchBasic compiling without failing completely?

Finally at the end of my rope, I write a script to compile all 397 individual source code files generated by wsdl2java. Lo and behold, that fixed it! Suddenly all of my previous problems were gone, all of the methods were accepting the documented datatypes, and life was good.

But there are still some open questions. Namely, what the heck was that all about? How did some of these classes compile correctly if other classes they referenced hadn't been compiled at all? What happened that changed the datatypes expected by so many of those methods? Is this an issue with ColdFusion? With Apache Axis? If you've run into similar issues connecting to web services using ColdFusion or have any insight into what could have caused this, I'd love to get an earful.


dizulli said...

God you're so smart. Wish you were older and in the mid-atlantic region. hehe

(I'm assuming this is like the other blog and you don't have to post non-tech-related comments:)

Later, Jeremy!

Jeremy said...

Hey, don't wish me older!! Wish me about 5 years younger. Those were the days!

dizulli said...

It's not so bad getting older, Little Brother. But if you really want me to then okay. I wish you were 5 years younger.

...... ....... did it work?