Skip to main content
HaroonTyagi
Known Participant
November 24, 2014
Question

How to get Soap Request xml in application.cfc

  • November 24, 2014
  • 1 reply
  • 3253 views

Hi

if api getting soap request using cfhttp like below:

<cfxml variable="mydata">

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

   <soapenv:Header />

   <soapenv:Body>

       <ns:service_soap_call soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">

        <login>test</login>

        <password>test</password>

      </ns:service_soap_call>

   </soapenv:Body>

</soapenv:Envelope>

</cfxml>

 

  <cfhttp url="http://sm.iclp-dubai.ae/research/wsdl/MyPointsBank.cfc?wsdl" method="post" charset="utf-8" result="myresult">

       type" value="text/xml">

        <cfhttpparam type="header" name="SOAPAction" value="">

       <cfhttpparam name="soapInput" type="xml" value="#trim(mydata)#"/>

</cfhttp>

then how to get Soap Request in application cfc.

like :

<cfif IsSOAPRequest() >

  <cfset soapreq = GetSOAPRequest() />

</cfif>

I want to validate the soap xml Request before calling targeted CFC.

Any suggestion!.

This topic has been closed for replies.

1 reply

BKBK
Community Expert
November 25, 2014

Why would you want to do that in Application.cfc? The whole idea behind the design of IsSOAPRequest() is that it is to be used within a CFC to indicate when the CFC is called as a web service. In your case, it would be appropriate to put it in MyPointsBank.cfc instead.

HaroonTyagi
Known Participant
November 25, 2014

Thanks BKBK,

I want to validate soap request before calling the targeted CFC method.
Consider this example if the soap request without the method body like below:

<cfxml variable="mydata">

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

   <soapenv:Header />

   <soapenv:Body>

      

   </soapenv:Body>

</soapenv:Envelope>

</cfxml>

then how to validate this and display proper fault code. In this case coldfusion generating a below exception:

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

   <soapenv:Body>

      <soapenv:Fault>

         <faultcode>soapenv:Server.userException</faultcode>

         <faultstring>java.lang.Exception: Body not found.</faultstring>

         <detail>

            <ns1:stackTrace xmlns:ns1="http://xml.apache.org/axis/">java.lang.Exception: Body not found.

at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java....

but I wan to display proper fault code.

Any Idea!

BKBK
Community Expert
November 26, 2014

My Dear BKBK if you check request xml above, then there is no function name(cfc component function: service_soap_call) and function body. So flow will not come inside a function and code will not execute.

Please could you make simple component like below:

Webservice.cfc

<cffunction name="service_soap_call" access="remote" output="no" returntype="any" >

      <cfargument name="str">

     <cfreturn arguments.str>

   </cffunction>

</cfcomponent>

if CFC component on your localhost then you can access web service url: http://localhost/Webservice.cfc?wsdl

then call this web service via this localhost url in your cfm with below below code:

CFhttp.cfm

<cfxml variable="mydata">
        <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wor="https://www.worldmilesafrica.com">
   <soapenv:Header/>
   <soapenv:Body>    
   </soapenv:Body>
</soapenv:Envelope>
</cfxml>

  <cfhttp url="http://localhost/Webservice.cfc?wsdl" result="myresult">
  <cfhttpparam type="header" name="content-type" value="text/xml">
        <cfhttpparam type="header" name="SOAPAction" value="">
  <cfhttpparam name="soapInput" type="xml" value="#trim(mydata)#"/>
</cfhttp>

<cfdump var="#myresult.fileContent#">

Please can try this example so you will have clear picture and understand correctly.

I am using ColdFusion 8 but I have checked in ColdFusion 11 same error.

thanks


HaroonTyagi wrote:

if you check request xml above, then there is no function name(cfc component function: service_soap_call) and function body.

No function name and body? This is confusing. You did define the following named function:

<cffunction name="service_soap_call" access="remote" output="no" returntype="any" >

</cffunction>