4 Replies Latest reply on Jun 9, 2009 10:37 AM by BKBK

    Passing XML Objects to a CFC via a webservice

    JimCumming

      Hi, I'm having a problem passing an xml object to a CFC via a webservice. My idea was to pass an xml object to a CFC, have the CFC extract some information from it, perform some operations and then build some xml to send back the client. I am using xml as the webservice needs to accept a dyanmic number and type of arguments. The problem I am having is that CF8 seems to treat XML received via a webservice differently to XML passed locally to a CFC.

       

      Here are some examples

       

          <cffunction name="sfrequest" description="I take some xml and do something" access="remote" returntype="any" output="false">
              <cfargument name="xmlRequest" type="xml" required="true">

                     <cfset xmlOutput = xmlRequest>

              <cfreturn xmlOutput />
          </cffunction>

       

      Will work if called locally or via a webservice

       

          <cffunction name="sfrequest" description="I take some xml and do something" access="remote" returntype="any" output="false">
              <cfargument name="xmlRequest" type="xml" required="true">

                     <cfset xmlRequest.request.xmlText = "A different value">

              <cfreturn xmlRequest />
          </cffunction>

       

      Will only work locally. If called as a webservice I get a java.lang.NoSuchFieldException : REQUEST error

       

      Trying to work out why this was happening I did a cfc like this to pass back the variables scope.

       

              <cffunction name="sfrequest" description="I take some xml and do something" access="remote" returntype="any" output="false">

                <cfargument name="xmlRequest" type="xml" required="true">

              <cfsavecontent variable="inputArgs">
                  <cfdump var="#arguments#">

              </cfsavecontent>
              <cfreturn inputArgs />

              </cffunction>

       

      When called locally I got back a dump of the xml that I passed in. However when I called it as a webservice I got something I believe to be a java class in it's place

       

      error.png

      Does anyone have any ideas???

        • 1. Re: Passing XML Objects to a CFC via a webservice
          BKBK Adobe Community Professional & MVP

          You should strive to make your web service universal. It should mean the same thing to a Coldfusion, Java or PHP caller.

           

          Note, for example, that a Coldfusion XML object or dump is meaningless to a Java or PHP client. Chances are, the XML or dump will break the WSDL. Then you don't even have a web service to start with. In many cases, it is sufficient for the service to return a string, which is as universal as you can get.

           

          There might be another problem in how you use Coldfusion to call a web service that returns XML. You should use cfhttp. Did you?

          • 2. Re: Passing XML Objects to a CFC via a webservice
            JimCumming Level 1

            Hi thanks for your answer.

             

            I am striving to make this webservice as universal as possible. I have only been returning dumps to my calling page to try and get a view of what's going on inside the component when I call it as a webservice. I wouldn't dream or returnin these back the client.

             

            The major core of this idea was to create a single component that acts as a facade for a number of other components. Because of this the component needs to accept and return a dynamically variable number of arguments. Because of this I selected xml as this seemed like the ideal solution; I can pass in an out some xml that contains all the arguments. I was hoping to reuse some internal functions to provide external webservices, and use this facade architechture to add a layer of security and logging which doesn't exist with the current functions.

             

            Do you have any suggestions of how I could best acheive something along these lines? Has someone already created a framework or methodology for creating webservices with Coldfusion which would provide this sort of functionality out of the box?

             

            Thanks again

             

            Jim

            • 3. Re: Passing XML Objects to a CFC via a webservice
              Jim-sama

              I use string as a platform neutral transport datatype for arguments and responses that are xml.

               

              This removes the hassle of dealing with having to re-interpret another language's object representation of xml.

              I receive xml, put it through IisXml(), then XmlParse(), then XmlValidate() against a schema. Then i know my data from my argument is good.

               

              When i return xml data, i use ToString(MyXml). This way, on the other side, whatever language is being used can convert the xml as string into whatever native object model they want by loading the string into that lang's parse() factory. for java, i personally use xerces or xmlbeans.

               

              If you have to use someone else's webservice and they don't send xml as string in the soap response, but rather xml in the actual soap response, then you can use GetSoapResponse(webserviceObjectVariable) to access the soap response in a coldfusion friendlier manner with it's native xml objects.

               

              -Jim

              • 4. Re: Passing XML Objects to a CFC via a webservice
                BKBK Adobe Community Professional & MVP
                Do you have any suggestions

                SOAP