Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

"Web Services and CF"


Published on

  • Be the first to comment

  • Be the first to like this

"Web Services and CF"

  1. 1. Building Service Oriented Architectures ColdFusion and Web Services
  2. 2. Agenda <ul><li>What are Web Services </li></ul><ul><li>How you can create and consume Web Services in ColdFusion </li></ul><ul><li>What are Service Oriented Architectures </li></ul><ul><li>Why are they important </li></ul><ul><li>How to create them </li></ul>
  3. 3. What is a Web Service <ul><li>W3C </li></ul><ul><li>Definition: A Web service is a software application identified by a URI, whose interfaces and binding are capable of being defined, described and discovered by XML artifacts and supports direct interactions with other software applications using XML based messages via internet-based protocols </li></ul>
  4. 4. My Definition <ul><li>Encapsulated, loosely coupled, contracted functions offered via standard protocols </li></ul>
  5. 5. Three Major Things <ul><li>Discovery/Description - WSDL </li></ul><ul><li>Publish - UDDI </li></ul><ul><li>Bind – WSDL and SOAP </li></ul>
  6. 6. Why WS/SOA’s <ul><li>Frankly it’s the best application architecture approach for large and distributed architectures. </li></ul><ul><li>More flexibility and more generic </li></ul><ul><li>Interoperability is predefined and key which leads to greater ROI, longer life cycles, greater usability </li></ul><ul><li>Makes more sense to “real people”  </li></ul><ul><li>Creates new opportunities for business, revenue, creativity, and over all usefulness </li></ul>
  7. 7. Web Services Stack Evolution
  8. 8. Buzz Word Stack
  9. 9. SOAP <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?> </li></ul><ul><li><SOAP-ENV:Envelope SOAP-ENV:encodingStyle=&quot;; xmlns:SOAP-ENV=&quot;;> </li></ul><ul><li><SOAP-ENV:Body> </li></ul><ul><li><SOAPSDK1:getTemperature xmlns:SOAPSDK1=&quot;capeconnect:AirportWeather:com.capeclear.weatherstation.Station&quot;> </li></ul><ul><li><arg0>KDCA</arg0> </li></ul><ul><li></SOAPSDK1:getTemperature> </li></ul><ul><li></SOAP-ENV:Body> </li></ul><ul><li></SOAP-ENV:Envelope> </li></ul>
  10. 10. SOAP <ul><li>Defines a unit of communication ( header,envelope, body) </li></ul><ul><li>Defines error handling through Soap fault </li></ul><ul><li>Defines extensibility usually through custom headers </li></ul><ul><li>Defines mechanism for representing abstract data including binary data, arrays, and complex data </li></ul><ul><li>Defines RPC – common format for distributed computation </li></ul><ul><li>Defines Document- Centric approach to information exchange (i.e. B2B) </li></ul>
  11. 11. SOAP- response <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><SOAP-ENV:Envelope xmlns:SOAP-ENV=&quot;; xmlns:xsd=&quot;; xmlns:xsi=&quot;; xmlns:SOAP-ENC=&quot;;> </li></ul><ul><li><SOAP-ENV:Body SOAP-ENV:encodingStyle=&quot;;> </li></ul><ul><li><cc1:getTemperatureResponse xmlns:cc1=&quot;capeconnect:AirportWeather:com.capeclear.weatherstation.Station&quot;> </li></ul><ul><li><return xsi:type=&quot;xsd:string&quot;>The Temperature at null is null</return></cc1:getTemperatureResponse></SOAP-ENV:Body></SOAP-ENV:Envelope> </li></ul>
  12. 12. Introducing Web Service and CF <ul><li>CF through CFINVOKE makes working with Web Services as easy as CFQUERY made working with Relation Databases </li></ul>
  13. 13. WSDL <ul><li> </li></ul><ul><li>WSDL is an XML format for describing network services as a set of endpoints operating on messages containing either document-oriented or procedure-oriented information. The operations and messages are described abstractly, and then bound to a concrete network protocol and message format to define an endpoint. Related concrete endpoints are combined into abstract endpoints (services). WSDL is extensible to allow description of endpoints and their messages regardless of what message formats or network protocols are used to communicate, however, the only bindings described in this document describe how to use WSDL in conjunction with SOAP 1.1, HTTP GET/POST, and MIME. </li></ul>
  14. 14. WSDL in layman's speak <ul><li>Defines what a service does – methods and operations </li></ul><ul><li>How a service is accessed – details of data formats and protocols necessary to services operations </li></ul><ul><li>Where a service is located – details of the protocol-specific network address, such as a URI/URL </li></ul>
  15. 15. WSDL in Specific <ul><li>portType- abstract interface definition like a java interface definition </li></ul><ul><li>Message- Defines the set of parameters referred to by method sigs or operations </li></ul><ul><li>Types – Data type def’s </li></ul><ul><li>Binding – contains details on how abstract interface is converted to literal representation (I.e. SOAP over HTTP) </li></ul><ul><li>Port – specifies actual service node endpoint (I.e. your http url) </li></ul><ul><li>Service – bad name. Actual a series or list of ports which you can think of as a collection of web services that model a complex business process </li></ul>
  16. 16. Data Mappings ColdFusion data type WSDL data type numeric SOAP-ENC:double boolean SOAP-ENC:boolean string SOAP-ENC:string array SOAP-ENC:Array binary xsd:base64Binary date xsd:dateTime guid SOAP-ENC:string uuid SOAP-ENC:string void (operation returns nothing) NA struct Map query QueryBean any complex type component definition complex type
  17. 17. ColdFusion Components (CFC) <ul><li><cfcomponent> </li></ul><ul><li><cffunction name=&quot;square&quot; returnType=&quot;string&quot; access=&quot;remote&quot;> </li></ul><ul><li><cfargument name=&quot;num1&quot; type=&quot;string&quot;> </li></ul><ul><li><cfset sum = #arguments.num1#*#arguments.num1#> </li></ul><ul><li><cfreturn #sum#> </li></ul><ul><li></cffunction> </li></ul><ul><li></cfcomponent> </li></ul>
  18. 18. Invocation <ul><li><cfinvoke </li></ul><ul><li>webservice = &quot; URLtoWSDL &quot; </li></ul><ul><li>method = &quot; operationName &quot; </li></ul><ul><li>inputParam1 = &quot;val1&quot; </li></ul><ul><li>inputParam2 = &quot;val2&quot; ... </li></ul><ul><li>returnVariable = &quot; varName &quot; > </li></ul>
  19. 19. WSDL – what we care about http://localhost:8500/xml/webservice/square.cfc?wsdl <ul><li><wsdl:message name=&quot;squareResponse&quot;> </li></ul><ul><li><wsdl:part name=&quot;return&quot; type=&quot;SOAP-ENC:string&quot; /> </li></ul><ul><li></wsdl:message> </li></ul><ul><li><wsdl:message name=&quot;squareRequest&quot;> </li></ul><ul><li><wsdl:part name=&quot;num1&quot; type=&quot;SOAP-ENC:string&quot; /> </li></ul><ul><li></wsdl:message> </li></ul>
  20. 20. Calling Square <ul><li><cfinvoke webservice=&quot;http://localhost:8500/xml/webservice/square.cfc?wsdl&quot; </li></ul><ul><li>method=&quot;square&quot; </li></ul><ul><li>num1=&quot;5&quot; </li></ul><ul><li>returnVariable=&quot;var1&quot;> </li></ul><ul><li></cfinvoke> </li></ul><ul><li><cfdump var=&quot;#var1#&quot;> </li></ul>
  21. 21. Same thing with CFSCRIPT <ul><li><cfscript> </li></ul><ul><li>ws = CreateObject(&quot;webservice&quot;, </li></ul><ul><li>&quot;http://localhost:8500/xml/webservice/square.cfc?wsdl&quot;); </li></ul><ul><li>resultVar = ws.getSquare(num1=“5&quot;); </li></ul><ul><li>writeoutput(var1); </li></ul><ul><li></cfscript> </li></ul>
  22. 22. Consuming Web Services <ul><li>Read the WSDL file </li></ul><ul><li>Get Parameters and figure data types </li></ul><ul><li>Use a invocation method </li></ul>
  23. 23. CFC Metadata
  24. 24. Show Metadata
  25. 25. getProducts <ul><li><cfcomponent> </li></ul><ul><li><cffunction name=&quot;getProducts&quot; returnType=&quot;query&quot; access=&quot;remote&quot; output =&quot;no&quot;> </li></ul><ul><li><cfargument name=&quot;ProductName&quot; type=&quot;string&quot; required=&quot;true&quot;> </li></ul><ul><li><cfquery name=&quot;prosearch&quot; datasource=&quot;icf&quot; dbtype=&quot;ODBC&quot;> </li></ul><ul><li>SELECT Product.ProductID, Product.ProductName, Product.ProductPricePerUnit, Product.VendorID </li></ul><ul><li>FROM Product </li></ul><ul><li>WHERE Product.ProductName LIKE '#arguments.ProductName#%' </li></ul><ul><li></cfquery> </li></ul><ul><li><cfreturn #prosearch#> </li></ul><ul><li></cffunction> </li></ul><ul><li></cfcomponent> </li></ul>
  26. 26. Complex Data <ul><li>http://localhost:8500/xml/webservice/productsearch.cfc?wsdl </li></ul><ul><li>CFC does not deal well with Queries and Structs </li></ul><ul><li><wsdl:message name=&quot;getProductsResponse&quot;> </li></ul><ul><li><wsdl:part name=&quot;return&quot; type=&quot;tns2:QueryBean&quot; /> </li></ul><ul><li></wsdl:message> </li></ul><ul><li><wsdl:message name=&quot;getProductsRequest&quot;> </li></ul><ul><li><wsdl:part name=&quot;ProductName&quot; type=&quot;SOAP-ENC:string&quot; /> </li></ul><ul><li></wsdl:message> </li></ul>
  27. 27. Dealing with Complex Data <ul><li>Minimize the use of ColdFusion complex types, such as query and struct, in the web services you create for publication. These types require consumers, especially those consuming the web service using a technology other than ColdFusion, to create special data structures to handle complex types. </li></ul>
  28. 28. Complex Data <ul><li><cfinvoke Webservice=&quot;http://localhost:8100/xml/webservice/productsearch.cfc?wsdl&quot; </li></ul><ul><li>method=&quot;getProducts&quot; </li></ul><ul><li>ProductName=&quot;ColdFusion&quot; </li></ul><ul><li>returnVariable=&quot;products&quot;> </li></ul><ul><li></cfinvoke> </li></ul><ul><li><cfdump var=&quot;#products#&quot;> </li></ul>
  29. 29. PRO’s of CFC Web Service <ul><li>Simple to deploy </li></ul><ul><li>Simple to consume </li></ul><ul><li>Based on industry standard/accepted AXIS </li></ul>
  30. 30. CONS to CFC’s Web Service <ul><li>Inability to customize headers </li></ul><ul><li>Issues with complex data </li></ul><ul><li>Only supports SOAP encoding style </li></ul><ul><li>Only Supports HTTP </li></ul><ul><li>No UDDI </li></ul>
  31. 31. Alternatives <ul><li>CFHTTP!! </li></ul><ul><li>CFOBJECT and MSXML </li></ul><ul><li>CFOBJECT and AXIS </li></ul><ul><li>CFX_API and AXIS </li></ul><ul><li>CFX,CFOBJECT, JSP SERVLET and other third party tools! </li></ul>
  32. 32. How SOA’s relate to Web Services <ul><li>service-oriented architectures are </li></ul><ul><ul><li>loosely coupled pieces of application functionality </li></ul></ul><ul><ul><li>published </li></ul></ul><ul><ul><li>consumed </li></ul></ul><ul><ul><li>and combined with other applications over a network. </li></ul></ul><ul><li>Web Services </li></ul><ul><ul><li>stack of emerging standards </li></ul></ul><ul><ul><li>define protocols </li></ul></ul><ul><ul><li>create a loosely coupled framework for programmatic communication among disparate systems </li></ul></ul>
  33. 33. SOA’s <ul><li>SOA’s are not so much a radical and disruptive technology paradigm shift like procedural to OO but a natural evolution of best practices. </li></ul>
  34. 34. SOA <ul><li>• Loosely Coupled . Senders and receivers (producers and consumers) are abstractly decoupled from each other. Senders construct self-contained messages (including but not restricted to XML documents) and send them using a standards-based communication backbone without knowing the actual location of the receiver. The communication mechanism is responsible for the abstraction between the sender and the receiver. </li></ul><ul><li>• Coarse Grained . Traditional object-based languages like Java expose their interfaces on a fine-grained, method basis. These fine-grained interfaces need to be aggregated into larger, coarse-grained services that closely resemble real business processes. Service technologies are designed to support the ability to assemble services into larger, more business suitable processes. </li></ul><ul><li>• Asynchronous . Asynchronous communication is essential for distributed architectures. Senders and receivers cannot always depend on the availability of each other to do their work. Through a system of intermediaries, messages are exchanged in real-time with high performance. Yet, when receivers are unavailable, the messages can be persisted for later </li></ul>
  35. 35. SOA <ul><li>STANDARS BASED : The connections are based upon vendor-independent standards . The development of generally open and accepted standards is a key strength of the coalitions that have been building web services infrastructure. Most previous efforts at distributed computing (e.g., CORBA, DCOM, RMI, and others) were very difficult to implement, because they were dependent upon a particular vendor’s product offering, highly specified, or programmatically complex—usually all of the above. </li></ul><ul><li>PROCESS CENTRIC : Systems are conceived from a process-centric perspective. By intent, services are designed with a task-orientation; they function as discrete steps in a larger workflow or business process. A well designed service describes its inputs and outputs in a way that other software can determine what it does, how to invoke its functionality, and what result to expect in return. </li></ul>
  36. 36. Why SOA’s <ul><li>Frankly it’s the best application architecture approach for large and distributed architectures. </li></ul><ul><li>More flexibility and more generic </li></ul><ul><li>Interoperability is predefined and key which leads to greater ROI, longer life cycles, greater usability </li></ul><ul><li>Makes more sense to “real people”  </li></ul><ul><li>Creates new opportunities for business, revenue, creativity, and over all usefulness </li></ul>
  37. 37. Distributed Process
  38. 38. Break Down of Process
  39. 39. SOA with CF <ul><li>Define at a high level of a process and then service </li></ul><ul><li>Create a open interface via CFC to other components, templates, tags </li></ul><ul><li>You can use getMetaData() to create automated apps and easily discoverable services </li></ul>
  40. 40. Change the way you think! <ul><li>SOA’s require you stop thinking about units of functionality, components, technology but force you to focus on what's important! Figuring out what you need to do and how to model it! </li></ul>
  41. 41. Implementations Today <ul><li>Re-Use and Syndication. Software re-use has always been a key part of component-based software models, but it rarely has been practical to implement. Web services may be different. Some early adopters envision syndicating existing software systems (e.g., an investment bank’s derivatives calculator or other complex algorithms) to partners and customers. Other re-use ideas include leveraging the standards-based interoperability to deliver data to a variety of formats and devices(e.g., web browsers, mobile devices, and interactive television). </li></ul><ul><li>Automation and Productivity. Disparate systems still result in a remarkable amount of manual integration processes. As a result, web services’ interoperability promise to yield tremendous opportunities for productivity improvements through automation of business processes and employee productivity. Example projects might include exposing order status tracking and past purchase history to customers. Automation initiatives could yield results similar to the so-called “ATM Effect,” which has helped significantly simplify the cost structure and increase the profitability of retail banking. </li></ul>
  42. 42. More Implementations <ul><li>Visibility into Operations. Businesses consistently seek to improve the accuracy of their inventory and revenue forecasts but are constrained by a lack of clear visibility into operating data. Web services based “digital dashboards” are one way adopters hope to address this challenge. Several specific categories of information that are hot-button issues include demand forecasting throughout the supply-chain, real-time cash flow and operating capital, and production and inventory availability.Bottom-line, better visibility will yield a dramatic impact on a company’s cost structure. </li></ul><ul><li>Exploring New Business Models. Most companies evaluating web services today are focused squarely on efficiencies and tend to put new web services-based revenue opportunities into a“sometime in the future” bucket. A few early adopters are exploring new subscription or pay-peruse business models, however. Further down the road, companies may spin off non-strategic (but potentially valuable) web service competencies, just as many tangible assets were “unlocked” at an increased value as stand-alone entities over the past ten years. </li></ul>
  43. 43. The Future <ul><li>Support for new protocols </li></ul><ul><li>Greater interoperability </li></ul><ul><li>Support for complex data types </li></ul><ul><li>Support for emerging standards </li></ul><ul><li>Exposure of the engine </li></ul><ul><li>Orchestration </li></ul>
  44. 44. Summary <ul><li>Super easy to consume and deploy </li></ul><ul><li>Supports emerging standards </li></ul><ul><li>Has issues with complex data, different encoding, as well as protocols </li></ul><ul><li>You have lots of options </li></ul><ul><li>Web Services and SOA’s are moving targets and paradigms and we will see change and growth in this space for several years </li></ul>
  45. 45. Resources <ul><li> </li></ul><ul><li> </li></ul><ul><li> </li></ul><ul><li> </li></ul><ul><li> </li></ul><ul><li> </li></ul><ul><li> </li></ul>