Not yet rated

Problem

You need to access a Web Service over HTTP protocol.

Solution

Use CFHTTP and send the required parameters.

Detailed explanation


In this example:
We will call a web-service located at  http://www.webservicemart.com/uszip.asmx?op=ValidateZip
This web service validates a US zip code. Visit the web service page to learn about it.

 

Calling a SOAP web service over HTTP requires the use of CFHTTP tag. We need to send the required headers and body with our CFHTTP call. That is exactly what the following example does:

<cfset intZipCode = "41001" />

<cfset strNS = " http://webservicemart.com/ws/" />
<cfset strWSUrl = " http://www.webservicemart.com/uszip.asmx?wsdl" />
<cfset strSOAPAction = " http://webservicemart.com/ws/ValidateZip" /> <cfoutput> <cfxml variable="requestWsdl"> <?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap=" http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd=" http://www.w3.org/2001/XMLSchema" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"> <soap:Body> <ValidateZip xmlns="#strNS#"> <ZipCode>#intZipCode#</ZipCode> </ValidateZip> </soap:Body> </soap:Envelope> </cfxml> </cfoutput> <cfhttp url="#strWSUrl#" METHOD="post" charset="utf-8"> <cfhttpparam name="SOAPAction" type="HEADER" value="#strSOAPAction#"> <cfhttpparam name="body" TYPE="XML" VALUE="#ToString(requestWsdl)#"> </cfhttp> <cfdump var="#cfhttp#" label="CFHTTP" /> <br/> <cfset response = XMLParse(cfhttp.fileContent) />
<cfdump var ="#response#" label="SOAP Response" />

+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes