a2d73ba15e24d1ec7870eb545a576bd8.ppt
- Количество слайдов: 18
XML Web Services Hints and Tips Bob Steemson Product Architect i. SOFT plc www. isoftplc. com 1
Introduction n Why use XML Web Services? n Some thoughts on XML n Building Web Service Code n Summary n Questions 2 THE HEALTH i. NNOVATOR www. isoftplc. com 2
Why Use XML Web Services? n Facilitates loose-coupling of applications n Platform Independent n Powerful XML tools available n Standard Internet technology lowers costs n Independent of proprietary platforms n Independent of expensive third party software n Open-source solutions available 3 THE HEALTH i. NNOVATOR www. isoftplc. com 3
Some Thoughts on XML is not about text n Understand use namespaces n Make use of XML Schemas n Make use of XSLT 4 THE HEALTH i. NNOVATOR www. isoftplc. com 4
XML is not about text n Don’t build XML Strings “by hand” n Use appropriate tools – For example MXXMLWriter, Xml. Writer, JDOM – Will handle illegal characters and buffer data – Will help ensure your XML is “well formed” n Don’t “pretty print” XML strings unnecessarily – Most XML will be passed from method to method or from machine to machine – View with tools like XML Spy or Internet Explorer – If necessary, include an option in test tools n Don’t keep parsing and serialising documents – Once parsed, keep as a DOM as long as possible 5 THE HEALTH i. NNOVATOR www. isoftplc. com 5
Understanding XML Namespaces n Prevent element and attribute names from different applications from clashing n XML Namespaces associate element and attribute names with a URI (URI or URN) – The URI is a way of defining a globally unique string – Two namespace URIs are equal if they are identical character-by-character (case sensitive) – There need not be a corresponding resource n Namespace prefix is a local synonym for URI – Avoids problems if URI contains illegal characters – Two names with different prefixes are identical if local names and URIs are the same 6 THE HEALTH i. NNOVATOR www. isoftplc. com 6
Using XML Namespaces n Always use namespaces for external XML – Anything that may be seen outside this application – Internal XML such as configurations may have no namespace if you are certain it will not “escape” n Avoid using the default namespace with no prefix – Reserve “no prefix” to mean “no namespace” – Can make writing XSLT more difficult n Beware of domain name changes if using a URL – Do not “hard code” the URL – URL changes require coordination with partners – Don’t forget Schema and XSL documents 7 THE HEALTH i. NNOVATOR www. isoftplc. com 7
Make use of XML Schemas n Create and publish a schema for each document n Validate input XML before processing by default – Allow validation to be turned off n Have an option to validate output documents – Use mainly for testing – Turn this off by default – “Buyer beware” 8 THE HEALTH i. NNOVATOR www. isoftplc. com 8
Make use of XSL Transformations n XSLT is a powerful way of transforming XML – Much more than a way of turning XML into HTML n Can change or remove document namespaces n Restructure elements or convert codes n Simplify complex external schemas – Can make serialisation & deserialisation simpler 9 THE HEALTH i. NNOVATOR www. isoftplc. com 9
Building Web Services n Designing Web Services n Security requirements n Think about testing n Don’t leave namespaces at the default n. NET Web Services Enhancements 10 THE HEALTH i. NNOVATOR www. isoftplc. com 10
Designing Web Services n Web Services should be “Coarse Grained” – Think of complex transactions that involve multiple co -operating objects, rather than object methods – Try to have fewer methods and extend functionality with options if necessary n Try to make stabilise service signatures - WSDL – Both ESI and the CHI Web Services have a single method that includes a service type parameter n Pass complex data as XML – Consider passing XML as a DOM Element rather than a string 11 THE HEALTH i. NNOVATOR www. isoftplc. com 11
Web Services Security n Keep security and other parameters separate – Both may change – but probably not at the same time n If possible, keep security credentials out of the SOAP body n Consider using WS-Security (see below) 12 THE HEALTH i. NNOVATOR www. isoftplc. com 12
Web Services Testing n Ensure that services can be tested in-house n When writing a new service – Write a simple interactive client for prototyping and early development – Create an automatic test client for long-term use n When writing a client for an external service – – 13 Provide a simple emulator for in-house testing Allows progress while connections are set up Allows future debugging in a closed environment Update the emulator after external testing THE HEALTH i. NNOVATOR www. isoftplc. com 13
Web Services Tracing n Use Web Services Tracing if all else fails n Can be useful in sorting out namespace issues n MS SOAP Toolkit (VB 6) includes Trace Utility n Apache SOAP includes Tcp. Tunnel. Gui class n. NET Web Services Enhancements classes have built in trace facilities 14 THE HEALTH i. NNOVATOR www. isoftplc. com 14
Use of Namespaces with SOAP n Tools such as the MS SOAP Toolkit and. NET will create WSDL files with default XML namespaces n Always take the time to override these with specific namespaces for your application 15 THE HEALTH i. NNOVATOR www. isoftplc. com 15
. NET Web Services Enhancements n Extension to standard. NET Web Services classes – Download from MSDN (current version 1. 0 SP 1) – Supports additional Web Services specifications that have been developed by Microsoft, IBM and other partners n WS-Security – Supports security tokens for authentication – Supports digital signing for message integrity – Supports encryption for confidentiality n WS-Routing – Route of Web Services requests via intermediaries n WS-Attachments – Allows attachments to SOAP messages 16 THE HEALTH i. NNOVATOR www. isoftplc. com 16
Summary n XML Web Services provide a simple and reliable way to connect applications n Based on well-established technologies n Cross-platform – but there are still grey areas n Easier to design and deploy than many alternatives such as DCOM or CORBA 17 THE HEALTH i. NNOVATOR www. isoftplc. com 17
Questions n Contact Details Bob. Steemson@isoftplc. com 18 THE HEALTH i. NNOVATOR www. isoftplc. com 18
a2d73ba15e24d1ec7870eb545a576bd8.ppt