web-services - 需要关于 cf 中 soap web 服务的一件小事的建议

标签 web-services soap coldfusion

请建议我使用 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/

相关文章:

java - 何时使用网络服务

java - 如何在soap webservice中添加 "content-type" header

java - 如何处理 Out Fault 拦截器中的运行时异常,Apache CXF

sql - 这是 Coldfusion 查询 SQL 注入(inject)证明吗?

coldfusion - ColdFusion 中获取季度第一天和最后一天的最快方法是什么?

java - 如何为并行 Web 服务请求配置线程池?

java - 我如何实际使用配置了 Spring 的 JAX-RS 客户端?

.net - 查看原始 XML 请求

json - 预期返回 JSON 的单元测试方法示例

javascript - asp.net webservice jquery填充文本框