gpt4 book ai didi

web-services - cfcomponent Web 服务 - 获取 SOAP 属性

转载 作者:行者123 更新时间:2023-12-04 05:17:12 24 4
gpt4 key购买 nike

这是一个 SOAP 请求示例:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:ws="http://ws_test">
<soapenv:Header/>
<soapenv:Body>
<ws:testService a1="a1" a2="a2">
<ws:e1>e1</ws:e1>
<ws:e2>e2</ws:e2>
</ws:testService>
</soapenv:Body>
</soapenv:Envelope>

这是我的示例 cfc Web 服务:
<cfcomponent style="document" wsversion = 1>
<cffunction name="testService" returntype="String" access="remote" >
<cfargument type="string" name="e1"/>
<cfargument type="string" name="e2"/>

<!--- Missing: code to extract a1 and a2 --->

<cfreturn "#e1# #e2#">
</cffunction>
</cfcomponent>

我是 Coldfusion 和 Web 服务的新手,我不知道如何提取属性 a1 a2 来自 <testService> ,用谷歌搜索但找不到任何引用。有任何想法吗?

=== 编辑 ===

认为如果我附加类型定义可能会有用:
<complexType name="testServiceType">
<sequence>
<element name="e1" type="string"></element>
<element name="e2" type="string"></element>
</sequence>
<attribute name="a1" type="string"/>
<attribute name="a2" type="string"/>
</complexType>

请注意,虽然这是我的测试 Web 服务,但它基于我们合作伙伴提供的数据模式,这意味着我的 Web 服务必须符合它。

=== 分辨率 ===

根据格里的回答,这就是我最终要做的:
<cfcomponent style="document" wsversion = 1>
<cffunction name="testService" returntype="String" access="remote" >
<cfargument type="string" name="e1"/>
<cfargument type="string" name="e2"/>

<cfset soapReq = getSOAPRequest()>
<cfset soapXML = xmlParse(soapReq)>
<cfset attributes = soapXML.Envelope.body.XmlChildren[1].XmlAttributes>

<cfset a1 = attributes.a1>
<cfset a2 = attributes.a2>

<cfreturn "#e1# #e2# #a1# #a2#">
</cffunction>
</cfcomponent>

最佳答案

根据您的评论,我认为您需要 getSoapRequest() 然后使用 keshav-jha 给出的答案中的代码解析它

<cfcomponent style="document" wsversion = 1>

<cffunction name="testService" returntype="String" access="remote" >
<cfargument type="string" name="e1"/>
<cfargument type="string" name="e2"/>
<cfscript>
soapReq=GetSOAPRequest();
soapXML=xmlParse(soapReq);
bodyAttributes = {
a1:soapXML.Envelope.body.XmlChildren[1].XmlAttributes.a1
,a2:soapXML.Envelope.body.XmlChildren[1].XmlAttributes.a2
};
return serializejson(bodyAttributes);
</cfscript>

</cffunction>
</cfcomponent>

关于web-services - cfcomponent Web 服务 - 获取 SOAP 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29002584/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com