Creating and Consuming Web Services wi

Document Sample
Creating and Consuming Web Services wi Powered By Docstoc
					  Creating and
Web Services with
    Chaz Chumley
    What will be Covered
   Understanding Web Services
   Creating Web Services
   Consuming Web Services
   Error Handling
   Best Practices
    About the Presenter
   8 yrs CF Experience
   Application Developer –
   Author/Partner –
   Instructor – University of Nevada Las Vegas
   Adobe User Group Manager – Las Vegas
   Frequent speaker: Conferences
        Understanding Web
       What is a web service
         Web based application
         Consumed over the Internet
         Communicates and exchanges data
         Application, platform, syntax agnostic
        Understanding Web
       How do web services work?
         SOAP – Simple Object Access Protocol
         a)   XML based protocol
         b)   Send and receive requests and responses

         WSDL – Web Services Descriptor Language
         a)   Describes arguments accepted
         b)   Describes methods & properties returned
    Creating Web Services
       What is involved?
         Simple ColdFusion Component
         Method access modifier set to “Remote”
         Return data as string
    Creating Web Services
       Building a Web Service - Exercise 1
         Create a new CFC – hello.cfc
         a)   Create new function called “getHello”
         b)   Set access = “remote”
         c)   Return string value

    <cfcomponent output="false">
         <cffunction name="getHello" access="remote" returntype="string">
              <cfreturn "Hello CFUnited" />
    Creating Web Services
       Testing a Web Service - Exercise 2
         Viewing the WSDL
         a) http://dev.cfunited/hello.cfc?wsdl

         Calling Web Service method via URL
         a)   http://dev.cfunited/hello.cfc&method=getHello
            Consuming Web
       How do I call a web service?
         CFObject tag
         CFInvoke tag
         CreateObject() function
              Consuming Web
       Using CFObject – Exercise 3
         Object representing web service
         Referencing Web Service Methods
         a)   Dot notation

    <cfobject webservice="http://dev.cfunited/hello.cfc?wsdl" name="ws">
            Consuming Web
       Using CFInvoke – Exercise 4
         Calls an instance of the web service

    <cfinvoke webservice="http://dev.cfunited/hello.cfc?wsdl"
              returnvariable="ws" />

              Consuming Web
       Using CreateObject() – Exercise 5
         Object representing web service
         Referencing Web Service Methods
         a)   Dot notation

    <cfset ws = createObject("webservice","http://dev.cfunited/hello.cfc?wsdl") />
Web Services Revisited
       Creating a more complex web service
         Web services with arguments – Exercise 6
         a)   Create new function called “getPersonalHello”
         b)   Add an argument called “firstName”
         c)   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" />
Web Services Revisited
       Calling a web service with arguments
         Passing named argument
         Using CFInvokeArgument

    <cfinvoke webservice="http://dev.cfunited/hello.cfc?wsdl"
         <cfinvokeargument name="firstName" value="Chaz" />

Web Services Revisited
       Consuming Third Party APIs
         SOAP based web services
         a)   Easy to consume
         b)   Type checked
         c)   Simply output returned result
         REST based web services
         a)   Lightweight – not a lot of extra xml markup
         b)   Called using CFHttp
         c)   Process result using XML functions
Web Services Revisited
       Consuming Yahoo Search Service
         a)   Get an Application ID
         b)   Download the SDK
         c)   Ray Camden's ColdFusion examples
               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
               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()
    Additional Resources
       Adobe Documentation
         ColdFusion MX 8 -- Web services

         ColdFusion Developer Center

       CommunityMX
         Consuming RSS Feeds in ColdFusion: Part 1
         Using the Google API from ColdFusion
         Consuming the CMX Web Service with ColdFusion
   Simple to expose CFCs as web services
   Can consume SOAP and REST services
   Powerful prebuilt APIs from Yahoo, etc.