Friday, November 2, 2012

Initiating web service objects using class files

If you want to call a webservice which uses more complex arguments then it's easier (or even best practice) to use class files in stead of recreating the objects by yourself. Here is how:

  1. Open your ColdFusion9/stubs/ folder.
  2. Make a call to the webservice using createObject:
    someWs = createObject("webservice", "http://addressToWsdlFile/?wsdl");
  3. Inspect the stubs folder and find the subfolder which is newly created, open it.
  4. There should be a whole subfolder structure which contains eventually some .class files. Copy the root (normaly this is something like a top level domain: com or net or such)
  5. Paste the folder structure to folder which is noted as a class path folder, or make a new folder and put this in the ColdFusion administrator (Server Settings > Java and JVM > ColdFusion Class Path) or in your server.cfc class path settings
  6. Restart ColdFusion (do not forget this!)
  7. Now you can create one of the objects needed in the webservice using:
    someObject = createObject("java", "com.test.testapp.testObj);
    (the dot notated path is corresponding with the copied folder structure to the class files)
  8. The objects should have all the getters and setters. (Use writeDump() (or cfdump) to see all the properties of the classes). So use someObject.setSomeValue("xxx"); to populate.
  9. Call the method with the generated object:
    result = someWs.someMethod(someObject);
  10. Done!


No comments:

Post a Comment