July 8, 2004

Web Services a quickie

Web Services is a term that has come to encompass the ways for discovering software as services accross the web. Services can be truly exploited with CFMX in a very easy manner.

Web services group together several different technologies, SOAP, WSDL, and UDDI. Simple Object Access Protocal, SOAP, is an XML envelope describing how to use and what is there. In addition within the envelop is the rules for how to process. WSDL or Web Services Description Language is an XML of the service interface and directions of how to use. UDDI is short for Universal Description, Discover, and Integration and is the way to describe a web service. UDDI registries allow business to publish and query existing web services.

Using Web Services is exceptionately easy with coldfusion.

For example here is a Service that calculates BMI: I had the file in the http://localhost/bmi/bmi.cfc of my development maching.

<cfcomponent>
<cffunction name="calculateBMI" access="remote" returntype="numeric" hint="This function calculates an individuals Body Mass Index">
<cfargument name="WeightLbs" type="numeric" required="yes" hint="The person's weight in pounds">
<cfargument name="HeightInches" type="numeric" required="yes" hint="The person's height in inches">
<cfset HeightInchesSquared = HeightInches * HeightInches>
<cfset WHI = WeightLbs / HeightInchesSquared>
<cfset BMI = WHI * 703>
<cfreturn DecimalFormat(BMI)>
</cffunction>
</cfcomponent>

And here is an example consuming that service


<cfinvoke webservice="http://localhost/bmi/bmi.cfc?wsdl" method="calculateBMI" returnvariable="varBMI">
<cfinvokeargument name="WeightLbs" value="140">
<cfinvokeargument name="HeightInches" value="72">
</cfinvoke>

And finally so everything is in one place here is an example of the wsdl for that service.


<?xml version="1.0" encoding="UTF-8" ?>
- <wsdl:definitions targetNamespace="http://bmi" xmlns:impl="http://bmi" xmlns:intf="http://bmi" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns1="http://rpc.xml.coldfusion" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/">
- <wsdl:types>
- <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://rpc.xml.coldfusion">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
- <complexType name="CFCInvocationException">
<sequence />
</complexType>
</schema>
</wsdl:types>
- <wsdl:message name="CFCInvocationException">
<wsdl:part name="fault" type="tns1:CFCInvocationException" />
</wsdl:message>
- <wsdl:message name="calculateBMIResponse">
<wsdl:part name="calculateBMIReturn" type="xsd:double" />
</wsdl:message>
- <wsdl:message name="calculateBMIRequest">
<wsdl:part name="WeightLbs" type="xsd:double" />
<wsdl:part name="HeightInches" type="xsd:double" />
</wsdl:message>
- <wsdl:portType name="bmi">
- <wsdl:operation name="calculateBMI" parameterOrder="WeightLbs HeightInches">
<wsdl:input name="calculateBMIRequest" message="impl:calculateBMIRequest" />
<wsdl:output name="calculateBMIResponse" message="impl:calculateBMIResponse" />
<wsdl:fault name="CFCInvocationException" message="impl:CFCInvocationException" />
</wsdl:operation>
</wsdl:portType>
- <wsdl:binding name="bmi.cfcSoapBinding" type="impl:bmi">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
- <wsdl:operation name="calculateBMI">
<wsdlsoap:operation soapAction="" />
- <wsdl:input name="calculateBMIRequest">
<wsdlsoap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://bmi" />
</wsdl:input>
- <wsdl:output name="calculateBMIResponse">
<wsdlsoap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://bmi" />
</wsdl:output>
- <wsdl:fault name="CFCInvocationException">
<wsdlsoap:fault use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://bmi" />
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
- <wsdl:service name="bmiService">
- <wsdl:port name="bmi.cfc" binding="impl:bmi.cfcSoapBinding">
<wsdlsoap:address location="http://localhost/bmi/bmi.cfc" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

Posted by Elyse at July 8, 2004 10:46 PM | TrackBack
Comments

Good article it clarified much. Only problem, when I tried to print this for easy reading, it really came out screwy on the printer.

Posted by: fats at July 27, 2004 10:39 AM
Post a comment









Remember personal info?