2 Replies Latest reply on Oct 26, 2007 6:54 AM by dacf

    Creating Web Service - Repeating data structure

      I am creating a Web Service in Coldfusion MX 7 and I am looking for help on its design.

      The problem is, one of the cffunction's called "calculateQuote" requires over 30 <cfargument...> statements to get all of the necessary input. To make matters worse, 10 of these arguments describe insurance policies as part of the quote and each policy can occur from 1 to many times. I am envisioning a <cffunction...> statement that is enormous.

      As an alternative, is it reasonable to have 1 <cfargument...> statement that contains an xml document that has all of the input? Would this be a strange thing to do or is it a "normal" way to write web services that require a lot of input data?

      Here is what I would assume the cffunction would look like...

      <cffunction access="remote" name="calculateQuote" output="false" returntype="???">
      <cfargument name="xmlQuoteInput" type="???" required="true">
      <cfset strucValidate = XmlValidate(ARGUMENTS.xmlQuoteInput,myXSDFile)> <!--- Validate the XML --->
      <cfset varXMLQuoteInput = XmlParse(ARGUMENTS.xmlQuoteInput)>
      ... and so on

      Thank you!
        • 1. Re: Creating Web Service - Repeating data structure
          dacf Level 1
          Can't do one arg with xml type if using a CFC as a web service, it won't create the WSDL correctly if you want ColdFusion to do it automatically and any consumer will not know what to pass into it unless you publish documentation saying exactly what you need.

          You need to use CFCs as Web service types here:
          http://www.adobe.com/go/tn_19169 has an example.

          For you, the rough structure for one way to do it would be (assuming your actual web service would be called WebService.cfc)

          - WebService.cfc
          - InsuranceQuotes.cfc
          - InsuranceQuoteType01.cfc
          - InsuranceQuoteType02.cfc
          - InsuranceQuiteType10.cfc

          Then, you would do the following as seen in the attached code.

          Note the type of [] on the InsuranceQuotes.cfc, this means an array of the CFC web service types.

          That is the rough answer, harder to give more details without hard code examples. You might be able to get rid of the intermediate InsuranceQuotes.cfc but at the moment this is the way I would do it.
          • 2. Re: Creating Web Service - Repeating data structure
            dacf Level 1
            propN in InsuranceQuoteTypeXX.cfc bit of code doesn't need to have a type of InsuranceQuoteType01[], that is a typo on my part