Copy link to clipboard
Copied
Hi everyone,
I'm having trouble converting this XML to a Struct.
<book_ids quantity="2">7,9</book_ids>
I'm supposed to pass that as a parameter to a remote Web Service using cfinvoke. Can anyone help out on how to convert that XML to a Coldfusion Struct???
Thanks in advance for any help!
JC
Copy link to clipboard
Copied
What is the Web Service expecting as a parameter? More information is needed.
-Carl V.
Copy link to clipboard
Copied
Hi Carl,
Here's the relevant part of the WSDL:
<s:element name="getBooks">
</s:sequence>
</s:complexType>
</s:element>
</s:extension>
</s:simpleContent>
</s:complexType>
Copy link to clipboard
Copied
While I don't have any insight on this (I don't work with web services much), the additional information should make it easier for others to assist you.
-Carl V.
Copy link to clipboard
Copied
You cannot, in general, convert XML into struct. An XML object has elements, which may or may not have attributes. The attributes have values and the element itself may have a "value" in the form of XMLText. Whereas, a struct basically has key-value pairs. As XML packs many more properties that a struct, a one-to-one mapping is often impossible.
In any case, there is little point converting the XML to a struct. A struct is typical ColdFusion lingo that wont be understood by webservices. I would suggest you send the XML itself to the service! How? As a SOAP message.
You could do something like this
!--- Web service WSDL --->
<cfset wsdl_url="http://mydomain.com/myws.cfc?wsdl">
<!--- Compose SOAP message to send to web service--->
<cfsavecontent variable="soap"><?xml version="1.0" encoding="UTF-8" ?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
soapenv:Body>
<book_ids quantity="2">7,9</book_ids>
</soapenv:Body>
</soapenv:Envelope>
</cfsavecontent>
<!--- Invoke web service and send message--->
<cftry>
<cfhttp url="#wsdl_url#" method="post" >
<cfhttpparam type="header" name="content-type" value="text/xml">
<cfhttpparam type="header" name="SOAPAction" value="">
<cfhttpparam type="header" name="content-length" value="#len(soap)#">
<cfhttpparam type="header" name="charset" value="utf-8">
<cfhttpparam type="xml" name="message" value="#trim(soap)#">
</cfhttp>
<p><cfoutput>#xmlFormat(cfhttp.fileContent)#</cfoutput> </p>
<cfcatch type="any">
<cfdump var="#cfcatch#">
</cfcatch>
</cftry>