3 Replies Latest reply on Aug 17, 2009 8:03 PM by Dan Bracuk

    How to create/call dynamic XML feed from CFC - HELP PLEASE!!

    slykiwi Level 1

      Hi All,

       

      First off I'm a newb to web services.  I'm trying to create the invoke a web service on a CFC for a XML feed.  When I call the CFC directly all looks fine and is correctly formatted etc:

       

      http://www.prevu.tv/cfc/xyzTest.cfc?method=listPlant

       

      Am I correct in outputting it in this way?  What if I output as a string instead......would others be able to consume it?

       

      When I try to invoke it as a web service I am getting an error I do not understand.  I am trying to call it using (user/pass not required in CFC):

       

      <cfinvoke webservice="test" method="listPlant" returnvariable="foo">
      <cfinvokeargument name="username" value="abc">
      <cfinvokeargument name="password" value="123">
      </cfinvoke>

       

      <cfoutput><cfdump var="#foo#"></cfoutput>

       

      Here is my CFC code:

       

      <cfcomponent>
          <cffunction name="listPlant" access="remote" returntype="xml" output="no">
          <cfargument name="username" type="string" required="no">
          <cfargument name="password" type="string" required="no">
              <cfquery datasource="#request.dsn#" name="getPlant">
              SELECT                *
              FROM                  plant
              INNER JOIN        plantaddress ON plant.plantID = plantaddress.plantID
              WHERE              icePlantID IS NULL
              AND                   categoryID NOT IN (9,10,11)
              AND                   statusID = 1
              AND                   activePlantList = 1
              ORDER BY        plant.plantID LIMIT 5
              </cfquery>
              <!---Convert Query to xml--->
              <cfprocessingdirective suppresswhitespace="Yes">
              <cfcontent type="text/xml; charset=utf-8">
              <cfxml variable="xmlobject">
              <PrevuPlant>
                  <cfoutput query="getPlant">
                  <Plant>
                      <PlantID>#plantID#</PlantID>
                      <PlantName>#XmlFormat(plantName)#</PlantName>
                      <Street>#XmlFormat(street)#</Street>
                      <Suburb>#XmlFormat(suburb)#</Suburb>   
                      <City>#XmlFormat(city)#</City>
                      <State>#XmlFormat(state)#</State>
                      <Country>#XmlFormat(country)#</Country>
                      <PostCode>#XmlFormat(postcode)#</PostCode>
                      <Latitude>#XmlFormat(latitude)#</Latitude>
                      <Longitude>#XmlFormat(longitude)#</Longitude>
                      <CountryCode>#XmlFormat(countryCode)#</CountryCode>
                      <AreaCode>#XmlFormat(areaCode)#</AreaCode>
                      <Phone>#XmlFormat(phone)#</Phone>
                      <Fax>#XmlFormat(fax)#</Fax>
                  </Plant>
                   </cfoutput> 
              </PrevuPlant>
              </cfxml>
              <!---Convert back to a string--->
              <cfset myvar=toString(xmlobject)>
              </cfprocessingdirective>
          <cfreturn myvar>
          </cffunction>
      </cfcomponent>

       

      Can anyone please tell me where I am going wrong, or how the output for a XML feed called from a CFC should look in a browser etc?

       

      Thanks