XML

Getting Started with RESTful Web Services in ColdFusion

In ColdFusion 10, we have added support for creating and publishing REST services. You can now make the ColdFusion components available as REST services so that various clients can access them. REST stands for Representational State Transfer. It is an architectural style based on web standards and HTTP protocol. The idea here is to use HTTP protocol instead of complex mechanisms such as CORBA, RPC, or SOAP to connect between the machines. In fact, you can imagine the World Wide Web, which is based on HTTP, as a REST-based architecture.

by Sagar H. Ganatra

Read the article here.

 

Invoking a Webservice Using CFHTTP

I found this article by James Netherton on a discussion list of CF-Brasil group.

I needed that long time ago, when I had to import some data from a PHP web application. I tried his code and it works perfectly, so I’m linking to his blog so you may use that code too if you need.

Invoking a Webservice Using CFHTTP

Here is his code for the component:

{code type=”coldfusion”}
<cfcomponent output=”false” style=”rpc”>
<cffunction name=”addNumbers” access=”remote” returntype=”numeric” output=”false”>
<cfargument name=”firstNumber” type=”string” required=”true”/>
<cfargument name=”secondNumber” type=”string” required=”true”/>
<cfreturn arguments.firstNumber + arguments.secondNumber/>
</cffunction>
</cfcomponent>
{/code}

Here is his code for the test:

{code type=”coldfusion”}

<!— You’d need to strip any whitespace before passing to CFHTTP —>
<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”>
<soapenv:Body>
<ns1:addNumbers soapenv:encodingStyle=”http://schemas.xmlsoap.org/soap/encoding/” xmlns:ns1=”http://directorypath”>
<firstNumber xsi:type=”xsd:string”>100</firstNumber>
<secondNumber xsi:type=”xsd:string”>10</secondNumber>
</ns1:addNumbers>
</soapenv:Body>
</soapenv:Envelope>
</cfsavecontent>

<!— Note that there’s no ?wsdl appendage to the url —>
<cfhttp url=”http://myserver/webservice.cfc” method=”post”>
<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)#”>
</cfhttp>

<!— Dump out a nice representation of the SOAP response —>
<cfdump var=”#xmlParse(cfhttp.FileContent)#”>
{/code}

Parsing Large XML File Into ColdFusion XML Object

Last week I had a big headache trying to import a 165MB XML file. I couldn’t even open it with any browse and reading it with ColdFusion gave me 500 errors, exceeded heap size, JRun closed connection, etc…

The solution I found was to read the file line-by-line using Java and creating blocks of XML code that allowed me to parse into objects and process them individually. Remembering, we use CF7 yet.

So I wrote this piece of code where I set my start tag and it will grab everything between my start and end tag, and assemble a XML object from there. I know the CF Gurus would suggest a much better solution, but that’s what i could accomplish with my humble knowledge and give a quick solution for the problem.

Read More…