Reputation: 547
I am far from expert in ColdFusion or XML, so this is probably a silly question. But is there a way to dynamically construct parts of a SOAP transaction, perhaps by including CFML within the transaction itself?? The API I am working with has a "MultiQuery" that allows a number of simple queries to be run within a single SOAP transaction. I want to use this feature to query using a bunch of Unique IDs that are provided by the previous web page. I don't know ahead of time how many IDs I will need to add to the "MultiQuery," so my thought was to pass each ID into an array on the page containing "MultiQuery," and then loop through the array ("allOfficers") to build the SOAP transaction, like this:
<cfset queryOpen=HTMLEditFormat("<arr:string>")>
<cfset queryClose=HTMLEditFormat("</arr:string>")>
<soapenv:Body>
<ser:MultiQuery>
<ser:associationGuid>e1c095ca39af</ser:associationGuid>
<ser:queries>
<cfloop index="i" from="1" to="#arrayLen(allOfficers)#">
<cfoutput>#queryOpen#</cfoutput>from Membership memb where memb.Owner='<cfoutput>#allOfficers[1]#</cfoutput>'<cfoutput>#queryClose#</cfoutput>
</cfloop>
</ser:queries>
</ser:MultiQuery>
</soapenv:Body>
Which of course does not work. When I output just the array, it produces nice output like this:
<arr:string>from Membership memb where memb.Owner='006e1c09-25f9-4178-86de-13c3e63200ce'</arr:string>
which is just the format I need for the SOAP envelope. But again, it does not work -- clearly it's the cfloop I am trying to use, because when I manually insert the output from the loop, the SOAP transaction works fine.
So, if anybody could give me some suggestions or get me pointed in the right direction, I sure would appreciate it. Again, I am bascially trying to dynamically add stuff to the SOAP transaction. Thanks in advance for your help!
UPDATE: here is the complete code I am using to try and build this SOAP request. Thank you all for your help!
<cfset queryOpen=HTMLEditFormat("<arr:string>")>
<cfset queryClose=HTMLEditFormat("</arr:string>")>
<cfloop index="i" from="1" to="#arrayLen(allOfficers)#">
<cfoutput>#queryOpen#</cfoutput>from Membership memb where memb.Owner='<cfoutput>#allOfficers[1]#</cfoutput>'<cfoutput>#queryClose#<br /></cfoutput>
</cfloop>
<cfsavecontent variable="soapBody">
<cfoutput>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:imp="http://test.com/Services/Imports" xmlns:ser="http://test.com/Services" xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<soapenv:Header>
<imp:SessionIdentifier Id="#URL.sessionGuid#"/>
</soapenv:Header>
<soapenv:Body>
<ser:MultiQuery>
<ser:associationGuid>12345</ser:associationGuid>
<ser:queries>
<cfloop index="i" from="1" to="#arrayLen(allOfficers)#">
<cfoutput>#queryOpen#</cfoutput>from Membership memb where memb.Owner='<cfoutput>#allOfficers[i]#</cfoutput>'<cfoutput>#queryClose#</cfoutput>
</cfloop>
</ser:queries>
</ser:MultiQuery>
</soapenv:Body>
</soapenv:Envelope>
</cfoutput>
</cfsavecontent>
<cfhttp url="https://test.com/Live/Partner/ObjectService" method="post" useragent="#CGI.http_user_agent#">
<cfhttpparam type="header" name="SOAPAction" value="http://test.com/Services/IObjectService/MultiQuery" />
<cfhttpparam type="header" name="accept-encoding" value="no-compression" />
<cfhttpparam type="xml" name="soapenv" value="#trim(soapBody)#" />
</cfhttp>
<cfset soapBody = xmlParse(cfhttp.fileContent) />
<cfset soapBody = soapBody['s:Envelope']['s:Body'].MultiQueryResponse.MultiQueryResult.Objects.ArrayOfanyType.anyType.Fields />
<cfset keyValue = xmlSearch(soapBody,"//*[local-name()='KeyValueOfstringanyType']") />
I can then loop over keyValue[] to build my page. The code as presented above does not work. When I take out the cfloop and replace it manually, it works. So i guess my question is, how can I add more queries to the queries section of the SOAP body? Or, is that even the right approach to be using? I do not know how many Chapter Officers each committee has, nor do I know their GUIDs until a user selects a chapter.
Hope this makes sense! Thanks again for your help!
Upvotes: 1
Views: 151
Reputation: 4234
You should see Ben Nadel's post on Making SOAP Web Service Requests With ColdFusion And CFHTTP
Also why are you doing lots of queries? Why not do the one?
<cfoutput>#queryOpen# from Membership memb where memb.Owner in (<cfqueryparam cfsqltype="cf_sql_integer" value="#arrayToList(allOfficers)#" list="true" > ) #queryClose#</cfoutput>
Upvotes: 1
Reputation: 586
why not put a <cfsavecontent>
tag around it and then dump it to the screen to see the output.
I don't see any <cfoutput>
tags there, but hard to guess if it is being executed as text or cfml
Upvotes: 2