user1728565
user1728565

Reputation: 117

Need suggestion on one small thing about soap web service in cf

Please suggest me what is the correct way to get method arguments in CF web service with SOAP

Below is my sample code for web service method where I didn't used <cfargument> but parsing 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 use <cfargument> in place of parsing xml request. Please suggest what is the correct way to do it.

Thanks in advance

Upvotes: 3

Views: 55

Answers (1)

Twillen
Twillen

Reputation: 1466

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 remote function to be accessed via SOAP requests. You don’t need to rely on the SOAP methods like isSOAPRequest() and GetSOAPRequest() unless you’re doing more complex tasks, such as requiring data in the SOAP header. You can view the SOAP wsdl by appending ?wsdl to the name of your component, such as localhost\yourService.cfc?wsdl

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

Upvotes: 1

Related Questions