7 Replies Latest reply on Nov 4, 2008 9:47 AM by BKBK

    passing xml to a web service

    jim1234 Level 1
      Hi all,

      I am trying to capture some xml that is being passed to a web service I am creating. I set the argument to an XML type. When I return the argument, the returned file content seems to approximate the XML being passed into the web service. However, I can't seem to access any of the XML from within the webservice.

      I tried doing a cfdump to a file within the web service of the XML and all I get are all the java object declarations, no XML. I try calling the java object functions and I get nothing. I tried accesing the XML elements using the ColdFusion syntax, and it says the elements doen't exist.

      So if anyone has a clue, it would be appreciated.

      Thanks,
      Jim
        • 1. Re: passing xml to a web service
          Level 7
          It's pretty difficult to divine what your problem might be without actually
          seeing any of your code.

          --
          Adam
          • 2. Re: passing xml to a web service
            jim1234 Level 1
            It's not really a problem per se, I just want to know how to pass data into a CF web service with an argument type of XML. Being able to access the XML just like you would any CF XML variable within the web service. I can't seem to get it to work, so if anyone has done this I would appreciate any insight.

            Thanks,
            Jim
            • 3. Re: passing xml to a web service
              Level 7
              > It's not really a problem per se, I just want to know how to pass data into a
              > CF web service with an argument type of XML. Being able to access the XML just
              > like you would any CF XML variable within the web service. I can't seem to get
              > it to work, so if anyone has done this I would appreciate any insight.

              It works the way you describe it. So given what you are describing doesn't
              seem to match what you're experiencing, I think perhaps looking at the code
              might be helpful.

              However rather than you just copy and paste what you've got so I can say
              "oh, hang on... that's not right", I've wasted some of my own time to write
              a proof of concept for you.

              <!--- caller.cfm --->
              <cfset o = createObject("webservice",
              " http://localhost:8305/shared/cf/webservices/sendXml/c.cfc?wsdl")>

              <cfxml variable="x1">
              <aaa>
              <bbb>ccc</bbb>
              </aaa>
              </cfxml>

              <cfset x2 = o.f(x=x1)>

              <cfdump var="#x1#" label="x1">
              <cfdump var="#x2#" label="x2">

              <!--- c.cfc --->
              <cfcomponent>

              <cffunction name="f" access="remote" returntype="xml">
              <cfargument name="x" type="xml" required="true">

              <cfset var a = xmlSearch(arguments.x, "//bbb")>
              <cfset a[1].xmlChildren[1] = xmlElemNew(arguments.x, "ddd")>
              <cfset a[1].xmlChildren[1].xmlText = "eee">
              <cfreturn arguments.x>
              </cffunction>

              </cfcomponent>

              Now, you see I don't know if that is actually some help for you, or even
              addresses your problem. But it at least demonstrates passing XML in, and
              back out, of a web service.

              If it doesn't cast any light on the scene... POST YOUR CODE!! ;-)


              --
              Adam
              • 4. passing xml to a web service
                BKBK Adobe Community Professional & MVP
                I expect Adam's method to work when the caller and the service are both in Coldfusion. However, a web service in .NET or Java might not know what to make of the XML variable, x1.

                There was a similar question in the forum some months ago. The universal way to pass an XML variable to a web service is by means of SOAP.




                • 5. Re: passing xml to a web service
                  Level 7
                  > I expect Adam's method to work when the caller and the service are both in
                  > Coldfusion. However, a web service in .NET or Java might not know what to make
                  > of the XML variable, x1.

                  True. But I figured when the OP said " I tried doing a cfdump to a file
                  within the web service" it pretty much demonstrated that the web service
                  *is* a CF one.

                  Although the reverse could be true: the calling code might not be CF. It's
                  harder to tell, based on what the OP is saying here, one way or the other.

                  It would be a lot less ambiguous and require less guessing if... [drum
                  roll]... we could see some code.

                  --
                  Adam
                  • 6. Re: passing xml to a web service
                    jim1234 Level 1
                    Ok, Thank You Adam for wasting your time to help me. Yes that worked. I didn't post any code because all I had was like four lines, I was trying to publish a ColdFusion webservice, another person has the consuming part. So this is all it was:

                    <cfcomponent>
                    <cffunction name="myFunction" access="remote">
                    <cfargument name="myArg" type="XML" required="true">

                    <cfdump var="#arguments.myArg#" output="c:\myoutput.txt">
                    </cffunction
                    </cfcomponent>

                    The problem was that the dump was the definition of the java object, not the XML. I didn't know how to access the XML part, or if it existed, which the xmlsearch does. Also, all the namespace prefixes are changed when the XML comes in, so if you have a tag like <myns:myelem></myns:myelem>, when it comes into the CF web service it's changed to <ns1:myelem></ns1:myelem>.

                    So the combination of those two was throwing me off.

                    Thanks for the help,
                    Jim
                    • 7. Re: passing xml to a web service
                      BKBK Adobe Community Professional & MVP
                      Adam Cameron wrote:
                      I figured when the OP said " I tried doing a cfdump to a file
                      within the web service" it pretty much demonstrated that the
                      web service *is* a CF one.


                      My post was a note of caution meant for Jim1234. Using SOAP would avoid some of the problems he has mentioned.

                      Your code looks good, no question about that. More, it answers the question.



                      .