Creating SOAP example using coldfusion

Many coldfusion programmer faces  a problem to connect SOAP with CFC. Here a example to fix the problem that explain how to connect SOAP with CFC?.

----callcfc.cfc----
<cfcomponent output="false" >
     <cffunction name="getelement" access="remote" returntype="any" output="false">
        <cfargument name="name" type="string" required="false"/>
        <cfargument name="firstNumber" type="numeric" required="false"/>
        <cfargument name="secondNumber"type="numeric" required="false"/>
        <cfreturn arguments.name & " Have " & arguments.firstNumber + arguments.secondNumber & " Point ">
     </cffunction>
</cfcomponent> 


-----Index.cfm
<cfsavecontent variable="soap"><?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
        xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://soap"> <!---CFC Folder Location --->

    <soapenv:Header>
      <setInit>1</setInit>
    </soapenv:Header>
   
    <soapenv:Body>
        <getelement soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" >
        <!---Highlight text is cfc method name --->
            <name>Pintu Kumar</name>
            <firstNumber>10</firstNumber>
            <secondNumber>20</secondNumber>
        </getelement>
       </soapenv:Body>
</soapenv:Envelope>
</cfsavecontent>


<cfhttp url="http://127.0.0.1:8500/Soap/callcfc.cfc?wsdl" method="post"> <!---Call CFC URL--->
    <cfhttpparam type="header" name="content-type" value="text/xml">
    <cfhttpparam type="header" name="SOAPAction" value="">
    <cfhttpparam type="header" name="content-length" value="#len(soap)#">
    <cfhttpparam type="header" name="charset" value="utf-8">
    <cfhttpparam type="xml" name="message" value="#trim(soap)#">
    <cfhttpparam type="header" name="Accept-Encoding" value="*" />
    <cfhttpparam type="Header" name="TE" value="deflate;q=0">
</cfhttp>
<cfdump var="#xmlparse(cfhttp.FileContent)#"><!---Print Return Dump --->





Comments

Popular posts from this blog

Login with facebook using coldfusion

Create CSV file in Coldfusion Using CFFile

Get Previous One Day Data in Sql Server