Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creating and Consuming Web Services with CFML

Similar presentations


Presentation on theme: "Creating and Consuming Web Services with CFML"— Presentation transcript:

1 Creating and Consuming Web Services with CFML
Chaz Chumley

2 What will be Covered Understanding Web Services Creating Web Services
Consuming Web Services Error Handling Best Practices June 27th- 30th 2007

3 About the Presenter 7 yrs CF Experience
Application Developer – Lucidus.net Author/Partner – CommunityMx.com Instructor – University of Nevada Las Vegas Adobe User Group Manager – Las Vegas Frequent speaker: Conferences June 27th- 30th 2007

4 Understanding Web Services
What is a web service Web based application Consumed over the Internet Communicates and exchanges data Application, platform, syntax agnostic June 27th- 30th 2007

5 Understanding Web Services
How do web services work? SOAP – Simple Object Access Protocol XML based protocol Send and receive requests and responses WSDL – Web Services Descriptor Language Describes arguments accepted Describes methods & properties returned June 27th- 30th 2007

6 Creating Web Services What is involved? Simple ColdFusion Component
Method access modifier set to “Remote” Return data as string June 27th- 30th 2007

7 Creating Web Services Building a Web Service - Exercise 1
Create a new CFC – hello.cfc Create new function called “getHello” Set access = “remote” Return string value <cfcomponent output="false"> <cffunction name="getHello" access="remote" returntype="string"> <cfreturn "Hello CFUnited" /> </cffunction> </cfcomponent> June 27th- 30th 2007

8 Creating Web Services Testing a Web Service - Exercise 2
Viewing the WSDL Calling Web Service method via URL June 27th- 30th 2007

9 Consuming Web Services
How do I call a web service? CFObject tag CFInvoke tag CreateObject() function June 27th- 30th 2007

10 Consuming Web Services
Using CFObject – Exercise 3 Object representing web service Referencing Web Service Methods Dot notation <cfobject webservice=" name="ws"> <cfoutput>#ws.getHello()#</cfoutput> June 27th- 30th 2007

11 Consuming Web Services
Using CFInvoke – Exercise 4 Calls an instance of the web service <cfinvoke webservice=" method="getHello" returnvariable="ws" /> <cfoutput>#ws#</cfoutput> June 27th- 30th 2007

12 Consuming Web Services
Using CreateObject() – Exercise 5 Object representing web service Referencing Web Service Methods Dot notation <cfset ws = createObject("webservice"," /> <cfoutput>#ws.getHello()#</cfoutput> June 27th- 30th 2007

13 Web Services Revisited
Creating a more complex web service Web services with arguments – Exercise 6 Create new function called “getPersonalHello” Add an argument called “firstName” Return argument in a string <cffunction name="getPersonalHello" access="remote" returntype="string"> <cfargument name="firstName" type="string" default="Insert Name Here" /> <cfreturn "Hello #arguments.firstName#, hope you enjoy CFUnited" /> </cffunction> June 27th- 30th 2007

14 Web Services Revisited
Calling a web service with arguments Passing named argument Using CFInvokeArgument <cfinvoke webservice=" method="getPersonalHello" returnvariable="ws"> <cfinvokeargument name="firstName" value="Chaz" /> </cfinvoke> <cfoutput>#ws#</cfoutput> June 27th- 30th 2007

15 Web Services Revisited
Consuming Third Party APIs SOAP based web services Easy to consume Type checked Simply output returned result REST based web services Lightweight – not a lot of extra xml markup Called using CFHttp Process result using XML functions June 27th- 30th 2007

16 Web Services Revisited
Consuming Yahoo Search Service Get an Application ID Download the SDK Ray Camden's ColdFusion examples June 27th- 30th 2007

17 Error Handling Any web service can throw errors
Using a Try, Catch block Web service stub caching Any changes won't reflect until refreshed Using CF Admin to refresh proxy/stub Programatically refreshing cache Handling Null Value Arguments Omit attribute June 27th- 30th 2007

18 Best Practices Creating a Web Service Alias
Similar to creating a mapping Reference web service url with friendly name Limiting access to Web Service Using isSoapRequest() June 27th- 30th 2007

19 Additional Resources Adobe Documentation CommunityMX
ColdFusion MX 7 -- Web services -- Version 7 ColdFusion Developer Center CommunityMX Consuming RSS Feeds in ColdFusion: Part 1 Using the Google API from ColdFusion Consuming the CMX Web Service with ColdFusion June 27th- 30th 2007

20 Summary Simple to expose CFCs as web services
Can consume SOAP and REST services Powerful prebuilt APIs from Yahoo, etc. Questions: June 27th- 30th 2007


Download ppt "Creating and Consuming Web Services with CFML"

Similar presentations


Ads by Google