Need a suggestion for one little thing about soap web service in cf

Please suggest me what is the correct way to get method arguments in CF webservice using SOAP

Below is a sample code for a web service method where I have not used < cfargument > but parsing the XML request

    <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>

      

But I think I should be using < cfargument instead of parsing the XML request. Please suggest how to do this correctly.

Thank you in advance

+3


source to share


1 answer


Your ColdFusion SOAP method can be as simple as:

<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 will allow access to remote functionality via SOAP requests. You don't have to rely on SOAP methods like isSOAPRequest()

and GetSOAPRequest()

unless you are doing more complex tasks like requiring data in the SOAP header. You can view SOAP wsdl by adding wsdl to your component name likelocalhost\yourService.cfc?wsdl

You can return any data type that ColdFusion can serialize. In my example, I decided to return a structure that will return the map to SOAP.

+1


source







All Articles