Transcript - Teamwork
The New Zealand Institute for Plant & Food Research Limited
Web Services:
Introduction & Design Considerations
Matthew Laurenson
History
Remote Procedure Calls (RPC) (~1976)
» allows a computer program to cause a subroutine or
procedure to execute in another [computer] without
programmer explicitly coding details (Wikipedia)
CORBA (1991)
» Allows RPC between programs written in different languages
» Problems
» Binary format
» Firewalls
SOAP (1998)
» RPC using XML over HTTP
The New Zealand Institute for Plant & Food Research
Limited
Web Services – benefits
Provide a service based on dynamic data
» Avoid need to distribute data
Maintain one copy of dynamic code
Share functionality between applications
Expose legacy applications
Deliver functionality as services to external clients
Decouple application modules
» clean designs
» freedom to change implementation
The New Zealand Institute for Plant & Food Research
Limited
Web Services – key concepts
WSDL
» (Pronounced Wizdle)
» Describes a Web Service (implemented using SOAP)
» XML Schema defines service in machine readable form
rpc/encoded -> doc/literal/wrapped style
» rpc/encoded style was initially favoured
» doc/literal more flexible, favoured by .Net so became default.
The New Zealand Institute for Plant & Food Research
Limited
Two basic design approaches
Most languages support generating a WSDL automatically
for services published as Web Services
Most languages support generating client code from a
WSDL
If you are coding the server, generate WSDL
automatically from application
If you are coding a client, generate code automatically
from WSDL
Stick with automatically generated client classes and/or
WSDL – don’t edit!
The New Zealand Institute for Plant & Food Research
Limited
Good design
Take advantage of power of XML-Schema features
Using typing, enumerations, ranges
Try to “chunk” work appropriately to reduce impact of
latency.
The New Zealand Institute for Plant & Food Research
Limited
Interoperability
Test interoperability early and often
Ingest WSDL into target languages
Play safe with things like element names
WS-I interoperability (www.ws-i.org/)
doc/literal/wrapped is where things have settled
Don’t use “overloaded” methods (same names, different
parameters)
Don’t use language-specific features (eg Java Maps) –
stick with arrays.
The New Zealand Institute for Plant & Food Research
Limited
Useful tools
Proxies
SOAPUI
The New Zealand Institute for Plant & Food Research
Limited
A RESTful life beyond SOAP
Object represented by unique URL
Get object contents using an HTTP GET
Modify the object using a POST
Advantages of REST web services:
» Lightweight - not a lot of extra xml markup
» Human Readable Results
» Easy to build - no toolkits required
SOAP advantages:
» Easy to consume - sometimes
» Rigid - type checking, adheres to a contract
» Development tools - generate client code
http://www.petefreitag.com/item/431.cfm
The New Zealand Institute for Plant & Food Research
Limited
JSON – alternative to XML
Javascript Object Notation
Used to serialize & transmit structured data
A subset of Javascript (but language independent)
Easier to parse in some situations
Somewhat more concise than XML
The New Zealand Institute for Plant & Food Research
Limited
Example of JSON
{ "firstName": "John",
"lastName": "Smith",
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021" },
"phoneNumber": [
{ "type": "home", "number": "212 555-1234" },
{ "type": "fax", "number": "646 555-4567" } ]
} http://en.wikipedia.org/wiki/JSON
The New Zealand Institute for Plant & Food Research
Limited