首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SOAP事务中的CFML?

SOAP事务中的CFML?
EN

Stack Overflow用户
提问于 2012-08-02 11:41:38
回答 2查看 128关注 0票数 1

我不是ColdFusion或XML方面的专家,所以这可能是一个愚蠢的问题。但是,有没有一种方法可以动态地构造SOAP事务的各个部分,比如通过在事务本身中包含CFML?我正在使用的应用程序接口有一个"MultiQuery“,它允许在单个SOAP事务中运行许多简单的查询。我想使用此功能来使用前一个网页提供的一组唯一ID进行查询。我事先不知道需要向"MultiQuery“添加多少个ID,所以我的想法是将每个ID传递到页面上包含"MultiQuery”的数组中,然后循环通过该数组("allOfficers")来构建SOAP事务,如下所示:

代码语言:javascript
复制
<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>

这当然不起作用。当我只输出数组时,它会产生如下所示的良好输出:

代码语言:javascript
复制
<arr:string>from Membership memb where memb.Owner='006e1c09-25f9-4178-86de-13c3e63200ce'</arr:string>

这正是我需要的SOAP信封格式。但是,它同样不起作用--很明显,这是我尝试使用的cfloop,因为当我手动插入来自循环的输出时,SOAP事务工作得很好。

所以,如果有人能给我一些建议或给我指明正确的方向,我将不胜感激。再次强调,我基本上是在尝试动态地向SOAP事务中添加内容。提前感谢您的帮助!

更新:下面是我用来尝试构建此SOAP请求的完整代码。感谢大家的帮助!

代码语言:javascript
复制
<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']") />

然后,我可以遍历keyValue[]来构建我的页面。上面显示的代码不起作用。当我拿出cfloop并手动替换它时,它工作了。所以我想我的问题是,如何向SOAP主体的查询部分添加更多查询?或者,这是使用的正确方法吗?我不知道每个委员会有多少分会官员,也不知道他们的GUID,直到用户选择一个分会。

希望这是有意义的!再次感谢您的帮助!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-08-02 21:40:06

为什么不在它周围放置一个<cfsavecontent>标记,然后将其转储到屏幕上以查看输出。

我在那里没有看到任何<cfoutput>标记,但是很难猜测它是以文本还是cfml形式执行的

票数 2
EN

Stack Overflow用户

发布于 2012-08-02 12:26:47

你应该看看Ben Nadel在Making SOAP Web Service Requests With ColdFusion And CFHTTP上的帖子

还有,你为什么要做这么多的查询?为什么不做这个呢?

代码语言:javascript
复制
<cfoutput>#queryOpen# from Membership memb where memb.Owner in (<cfqueryparam cfsqltype="cf_sql_integer" value="#arrayToList(allOfficers)#" list="true" > ) #queryClose#</cfoutput>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11770745

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档