1 / 20

Web Services in ColdFusion 7

Web Services in ColdFusion 7. JaxFusion November, 2006. About the Presenter. David Fekke API Team Integration Developer Working with SOAP based Web Services since 2002 when .NET 1.0 was released. What will be Covered. SOAP standard WSDL files Creating Web Services Consuming Web Services

didier
Télécharger la présentation

Web Services in ColdFusion 7

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Web Services in ColdFusion 7 JaxFusion November, 2006

  2. About the Presenter • David Fekke • API Team • Integration Developer • Working with SOAP based Web Services since 2002 when .NET 1.0 was released

  3. What will be Covered • SOAP standard • WSDL files • Creating Web Services • Consuming Web Services • SOAP Headers in 6.1 and 7.0 • RPC vs Document style • REST vs SOAP • Cross Platform issues • Changing location endpoints

  4. SOAP standard • Simple Object Access Protocol • Based on XML over HTTP • Used for application to application communication • It is platform and language agnostic • Came from XML-RPC • SOAP standard ratified in 2001 • ColdFusion uses Apache Axis

  5. WSDL • Web Service Description Language • XML file that describes methods, parameters, data point and service address location • 11 parts to a WSDL file • Four different styles, but only two supported by ColdFusion 7

  6. <?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions targetNamespace="http://DefaultNamespace" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://DefaultNamespace" xmlns:intf="http://DefaultNamespace" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns1="http://rpc.xml.coldfusion" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <!--WSDL created by Macromedia ColdFusion MX version 7,0,2,142559--> <wsdl:types> <schema targetNamespace="http://rpc.xml.coldfusion" xmlns="http://www.w3.org/2001/XMLSchema"> <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/> <complexType name="CFCInvocationException"> <sequence/> </complexType> </schema> </wsdl:types> <wsdl:message name="echoResponse"> <wsdl:part name="echoReturn" type="xsd:string"/> </wsdl:message> <wsdl:message name="echoRequest">

  7. Creating Web Services • CFCs are used to create Web Services • Method access modifier set to “Remote” • Duck typing should not be used with SOAP or Flash Remoting • Avoid using complex types such as Structures, multi-dimensional arrays, Query objects

  8. <cfcomponent name="EchoService" displayname="myEchoService" hint="Echos a string"> <cffunction name="echo" hint="This echos a string back to the caller" access="remote" output="false" returntype="String"> <cfargument name="inString" type="String" required="true" /> <cfset var returnString = "" /> <cfset returnString = arguments.inString /> <cfreturn returnString /> </cffunction> </cfcomponent>

  9. Consuming Web Services • CFObject tag • CFInvoke tag, CFInvokeArgument tag • CreateObject() function • wsObj = createObject(“webservice”,”http://localhost/EchoService.cfc?wsdl”) • returnValue = wsObj.echo(“Echo this string”)

  10. Handling Complex return values • Hosting CF based SOAP, use separate CFC with CFProperty tags instead of structures to describe in the WSDL file. • CFDump tag really good for debugging • Complex values look like Java objects to ColdFusion

  11. SOAP Headers • Different ways of handling in 6.1 and 7 • Some vendors require SOAP headers • Different from cgi.Headers

  12. SOAP Headers in 6.1 • Requires patch after 6.1 or the 6.1 updater • Adobe has UDFs that mimic most of the behavior in 7 • Create a HeaderElement using Java object • "org.apache.axis.message.SOAPHeaderElement“ • Pass to setHeader method

  13. <cfset WSObj = createObject("webservice","https://www.somecompany.com/services/somews.asmx?wsdl") /> <cfset doc = XMLNew() />               <cfset doc.Authentication = XmlElemNew(doc, "https://www.somecompany.com/services/ ", "Authentication") /><cfset doc.Authentication.username = XmlElemNew(doc, "username") /><cfset doc.Authentication.username.XmlText = "myUsername" /><cfset doc.Authentication.password = XmlElemNew(doc, "password") /><cfset doc.Authentication.password.XmlText = "myPassword" /> <!--- <Authentication>   <username>myUsername</username>   <password>myPassword</password></Authentication> - <cfset jXMLdoc = doc.getDocumentElement() /> <cfset headerElement = createObject("java","org.apache.axis.message.SOAPHeaderElement") /><cfset headerElement.init(jXMLdoc) /><cfset WSObj.setHeader(headerElement) /> <cfset responseValue = WSObj.makeWSCall() />

  14. SOAP Headers in 7 • Built-in methods • AddSOAPRequestHeader() • AddSOAPResponseHeader() • GetSOAPRequestHeader() • GetSOAPResponse() • GetSOAPResponseHeader() • IsSOAPRequest() • GetSOAPRequest()

  15. RPC vs Document style • Style attribute in the cfcomponent tag • <cfcomponent style="document"> • Default style is RPC • Common WSDL styles are RPC/encoded and Document/literal and are supported by ColdFusion

  16. REST vs SOAP • Representational State Transfer • Simple HTTP get or post • REST popular with AJAX applications because of simplicity • REST does not require verbose XML like SOAP • SOAP based on standard XML syntax • SOAP libraries can handle extra complexity

  17. Cross Platform issues • Java and .NET support types not supported by standard SOAP types • DataSet is supported by .NET • Standard XML types supported • Fix is to serialize XML into a string

  18. Changing location endpoints • Endpoint is the URL for the web service • Default endpoint is set in the WSDL file • ws = CreateObject("webservice", "http://localhost/service.cfc?WSDL"); • ws._setProperty("javax.xml.rpc.service.endpoint.address", "http://92.169.1.20/service.cfc");

  19. Useful tools • CFusionMX/runtime/bin/sniffer.exe • http://www.soapclient.com/ • MicroSoft Fiddler • NetBeans 5 Web Service

  20. Links • http://tjordahl.blogspot.com/2005/12/changing-target-endpoint-on-web.html • http://www.macromedia.com/go/tn_18939 • http://www.fekke.com/blog/index.cfm/2005/9/21/UsingSOAPRequestHeadersinCFMX61 • http://www.fekke.com/blog/index.cfm/2006/6/9/Make-SOAP-based-Web-service-calls-with-Spry • http://rip747.wordpress.com/2006/10/30/dotnet-dataset-to-cf-structure-of-queries/

More Related