XML Web Services Practical Hints and Tips
Download
Report
Transcript XML Web Services Practical Hints and Tips
XML Web Services
Hints and Tips
Bob Steemson
Product Architect
iSOFT plc
www.isoftplc.com
1
Introduction
Why use XML Web Services?
Some thoughts on XML
Building Web Service Code
Summary
Questions
2
THE HEALTH iNNOVATOR
www.isoftplc.com
Why Use XML Web Services?
Facilitates loose-coupling of applications
Platform Independent
Powerful XML tools available
Standard Internet technology lowers costs
Independent of proprietary platforms
Independent of expensive third party software
Open-source solutions available
3
THE HEALTH iNNOVATOR
www.isoftplc.com
Some Thoughts on XML
XML is not about text
Understand and use namespaces
Make use of XML Schemas
Make use of XSLT
4
THE HEALTH iNNOVATOR
www.isoftplc.com
XML is not about text
Don’t build XML Strings “by hand”
Use appropriate tools
– For example MXXMLWriter, XmlWriter, JDOM
– Will handle illegal characters and buffer data
– Will help ensure your XML is “well formed”
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
Don’t keep parsing and serialising documents
– Once parsed, keep as a DOM as long as possible
5
THE HEALTH iNNOVATOR
www.isoftplc.com
Understanding XML Namespaces
Prevent element and attribute names from
different applications from clashing
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
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 iNNOVATOR
www.isoftplc.com
Using XML Namespaces
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”
Avoid using the default namespace with no prefix
– Reserve “no prefix” to mean “no namespace”
– Can make writing XSLT more difficult
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 iNNOVATOR
www.isoftplc.com
Make use of XML Schemas
Create and publish a schema for each document
Validate input XML before processing by default
– Allow validation to be turned off
Have an option to validate output documents
– Use mainly for testing
– Turn this off by default – “Buyer beware”
8
THE HEALTH iNNOVATOR
www.isoftplc.com
Make use of XSL Transformations
XSLT is a powerful way of transforming XML
– Much more than a way of turning XML into HTML
Can change or remove document namespaces
Restructure elements or convert codes
Simplify complex external schemas
– Can make serialisation & deserialisation simpler
9
THE HEALTH iNNOVATOR
www.isoftplc.com
Building Web Services
Designing Web Services
Security requirements
Think about testing
Don’t leave namespaces at the default
.NET Web Services Enhancements
10
THE HEALTH iNNOVATOR
www.isoftplc.com
Designing Web Services
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
Try to make stabilise service signatures - WSDL
– Both ESI and the CHI Web Services have a single
method that includes a service type parameter
Pass complex data as XML
– Consider passing XML as a DOM Element rather than
a string
11
THE HEALTH iNNOVATOR
www.isoftplc.com
Web Services Security
Keep security and other parameters separate
– Both may change – but probably not at the same time
If possible, keep security credentials out of the
SOAP body
Consider using WS-Security (see below)
12
THE HEALTH iNNOVATOR
www.isoftplc.com
Web Services Testing
Ensure that services can be tested in-house
When writing a new service
– Write a simple interactive client for prototyping and
early development
– Create an automatic test client for long-term use
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 iNNOVATOR
www.isoftplc.com
Web Services Tracing
Use Web Services Tracing if all else fails
Can be useful in sorting out namespace issues
MS SOAP Toolkit (VB6) includes Trace Utility
Apache SOAP includes TcpTunnelGui class
.NET Web Services Enhancements classes have
built in trace facilities
14
THE HEALTH iNNOVATOR
www.isoftplc.com
Use of Namespaces with SOAP
Tools such as the MS SOAP Toolkit and .NET will
create WSDL files with default XML namespaces
Always take the time to override these with
specific namespaces for your application
15
THE HEALTH iNNOVATOR
www.isoftplc.com
.NET Web Services Enhancements
Extension to standard .NET Web Services classes
– Download from MSDN (current version 1.0 SP1)
– Supports additional Web Services specifications that have
been developed by Microsoft, IBM and other partners
WS-Security
– Supports security tokens for authentication
– Supports digital signing for message integrity
– Supports encryption for confidentiality
WS-Routing
– Route of Web Services requests via intermediaries
WS-Attachments
– Allows attachments to SOAP messages
16
THE HEALTH iNNOVATOR
www.isoftplc.com
Summary
XML Web Services provide a simple and reliable
way to connect applications
Based on well-established technologies
Cross-platform – but there are still grey areas
Easier to design and deploy than many
alternatives such as DCOM or CORBA
17
THE HEALTH iNNOVATOR
www.isoftplc.com
Questions
Contact Details
[email protected]
18
THE HEALTH iNNOVATOR
www.isoftplc.com