请建议我使用 SOAP 在 CF Web 服务中获取方法参数的正确方法是什么
下面是我的 web 服务方法的示例代码,我没有使用 <cfargument>,而是解析 xml 请求
<cffunction name="Method1" displayname="method name" description="method description
"access="remote" output="true" returntype="xml">
<cfset isSOAP = isSOAPRequest()>
<cfif isSOAP>
Get the first header as a string.
<cfset reqxml = GetSOAPRequest()>
<cfset reqxml1 = XmlParse(reqxml)>
<cfset responseNodes = xmlSearch(#reqxml1#,"soapenv:Envelope/soapenv:Body") />
<cfset responseNodes = xmlparse(responseNodes[1]) />
<cfif structKeyExists( responseNodes.xmlroot, "AgentID" )>
<CFSET AgentID=trim(responseNodes.xmlroot.AgentID.xmltext)>
<cfelse>
<cfset process = 0 >
<cfset responce['ErrorCode'] = "MG1000">
<cfset responce['ErrorMessage'] = "Agent ID not found in request">
<cfset AnythingToXML = createObject('component', 'AnythingToXML.AnythingToXML').init() />
<cfset myXML = AnythingToXML.toXML(responce,"StatusResponse") />
<cfset result = xmlparse(myXML)>
<cfreturn result>
</cfif>
但我认为我应该使用 <cfargument> 代替解析 xml 请求。 请建议正确的方法是什么。
提前致谢
最佳答案
您的 ColdFusion SOAP 方法可以像这样简单:
<cffunction name="yourMethod" access="remote" output="false" returntype="struct">
<cfargument name="testString" type="String" >
<cfset local.out = structNew()>
<cfset local.out.argIn = arguments.testString>
<cfset local.out.additionalValue = "Hello World">
<cfreturn local.out>
</cffunction>
ColdFusion 将允许通过 SOAP 请求访问远程功能。您不需要依赖 isSOAPRequest()
和 GetSOAPRequest()
等 SOAP 方法,除非您正在执行更复杂的任务,例如需要 SOAP header 中的数据.您可以通过将 ?wsdl 附加到您的组件名称来查看 SOAP wsdl,例如 localhost\yourService.cfc?wsdl
您可以返回 ColdFusion 可以序列化的任何数据类型。在我的示例中,我选择返回一个结构,它将返回 SOAP 中的映射。
关于web-services - 需要关于 cf 中 soap web 服务的一件小事的建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26735418/