WS-BPEL 2.0 Tutorial
Author: Antony Miguel, Last Updated 19th April 2006
If you found this tutorial useful or lacking in any way or if you think there are certain areas which could be better explained or more fully explained please Let Me Know.
Contents
-
This tutorial assumes that the reader has some basic familiarity with XML. For a quick tutorial on XML try here at w3schools.com.
Because BPEL maps quite well to an existing set of concepts in other programming languages and technical subjects, the
tutorial will be interspersed with 'Analogy' sections which will hopefully help the reader to understand BPEL in the
context of some more familiar language or subject. These sections will look like this...
Analogy
(Programming) A BPEL <flow> activity is like launching multiple threads, and then waiting for them
to complete.
(Real World) A BPEL <flow> activity is like asking a bunch of people to do different things for you at the
same time, and then waiting for them all to get back to you and tell you they've finished before you do anything else.
-
Web Services Business Process Execution Language (WS-BPEL) is an XML based programming language to describe high level
business processes. A 'business process' is a term used to describe the interaction between two businesses or two
elements in some business. An example of this might be company A purchasing something from company B. BPEL allows
this interaction to be described easily and thoroughly such that company B can provide a Web Service and company
A can use it with a minimum of compatibility issues.
Overview - What is a Web Service?
-
In terms of BPEL, the term 'Web Service' means something with which you can interact. For example, you could
have a web service which you can interact with to get the time of day, or a web service you can interact with to buy
a fridge. The web service can have any purpose.
A Web Service is typically described using Web Service Description Language (WSDL). This is another XML based language
which allows you to describe the interface to the web service.
WSDL tells you exactly how you can interact with the web service but says nothing about how the web service works. This
forces you to rely on only the description of the web service rather than anything in the implementation - which helps
to reduce (maybe even eradicate) compatibility problems between two web services which provide the same function, but
use different implementations.
Analogy
(Programming) WSDL is like an interface or an abstract class. It tells you what the API is to the web
service but it doesn't tell you anything about the implementation.
(Real World) A WSDL document is like a set of instructions for a household appliance. The instructions tell you
how to use the appliance but they don't tell you how the appliance will do what it does. They tell you everything you
need to know about how to use a toaster but they don't tell you the details of how the toaster does it.
Overview - So whats so great about Web Services?
-
Web Services also have some other nice features which make them useful for describing interactions or
services.
Platform independance. A web service is described in WSDL which is a well defined language which any computer or
operating system can understand. This means that whether you're running a Mac or a PC or a mobile phone, everyone is
speaking the same well defined language.
Distributed. Web services and WSDL are designed so that when you describe an interface, you don't say anything about
where the web service is or where you are when you talk to it. So if a web service is something running on your
computer or something available on the internet, the web service description looks the same, only the 'address' of the
web service changes.
Overview - Where does BPEL fit in?
-
BPEL allows you to write programs that use web services, and to write programs that are web services.
Using BPEL you can write a program that uses a web service to fetch the weather forecast for your postcode (zip code),
check whether it will be raining this weekend and use another web service to send you an SMS message telling suggesting
that you go shopping (if its raining) or go to the beach (if its sunny). This might not be the most useful BPEL program
but every time a new web service turns up which lets you do or access something else (either as something you can download onto your computer and use, or as
a public web service available on the internet) the possibilities get broader and broader.
Also using BPEL, you could write the same program as above, but make the expose the whole thing as
a web service in it's own right. Other web service clients could connect to you and ask what they should do this weekend based
on their postcode.
Overview - Does that mean I have to use the internet just to print 'Hello World'?
-
No. Remember that a web service is just a description of a service - it doesn't say anything about where it is
or how it works. In order to be actually useful, a web service description must also contain a 'binding'. This
binding specifies what the implementation of the web service is. A common binding is SOAP/HTTP which uses the
XML Simple Object Access Protocol (SOAP) over HTTP (standard web page fetching language) to speak to web services
which are on the internet. Another common binding is the Java binding. This binding allows you to define local
in-process java implementations which implement web services.
So if you wanted to write a web service that allowed clients to print things (e.g. 'Hello World') you could write
it in Java and then expose it as a web service.
Overview - BPEL servers and the B2J reference BPEL engine
-
In most cases, BPEL is used as a server side programming language. This means that companies will often either deploy
BPEL as something to serve and track a customer request or they will deploy a BPEL server as a nice easy to use proxy to
all their legacy systems.
In either case, a common chain of events will be as follows:
- Web Service client (user) requests something from the server (perhaps via a browser or another server)
- Client request is received by the BPEL server.
- Client request is identified as a new request and a new BPEL process is used to serve that client
- Client continues to interact with the BPEL process, making requests etc, until the interaction is complete
- BPEL process disappears and client goes about it's business
- User writes a BPEL program as a series of steps to carry out
- User runs BPEL program
- One single copy of the BPEL program is created and immediately executed
- The running program logs information via local web services
- The program finishes and the user can look at the logs
This automatic creation of BPEL process instances in response to client requests is called 'create on demand'. The B2J reference BPEL engine has a different focus. It's primary focus is to act as an execution engine which can be programmed using BPEL. For an explanation why, take a look at the B2J Architecture Document. The common chain of events for the B2J BPEL engine is therefore slightly different:
In short, the B2J engine doesn't do 'create on demand'.
-
BPEL is an XML programming language. As a programming language it has three basic
components:
- Programming logic
- Data types
- Input/Output (I/O)
- Programming logic - BPEL
- Data types - XSD (XML Schema Definition)
- Input/Output (I/O) - WSDL (Web Services Description Language)
Hello World BPEL program
Importing WSDL and XSD files
PartnerLink definitions
Analogy
(Programming) ?
(Real World) a web service is like a description of how to phone a restaurant - you phone up, tell them your address
and you place an order for some food. A partner link is like bit of paper which has on it a phone number
for a particular restaurant - you can use the partner link to speak to a specific restaurant (web service).
The actual phone number of the restaurant is called the 'endpoint address' and is defined either in the WSDL
or in the BPEL (where it may be copied into an existing partnerLink to speak to a different restaurant).
Variable definitions
Variable assignment
Web Service Invocation
Analogy
(Programming) Invoking a web service is similar to invoking a function or a method on an API or an object.
One important difference though is that BPEL doesn't have any reference to that object or API, it only knows
how to speak to it (WSDL definition) and the address of the implementation (the endpoint reference). The
mechanics of getting to the implementation specified by the endpoint reference is not dealt with by BPEL.
(Real World) Invoking the web service is akin to actually making the call to the restaurant. The
variable defined previously holds the information you need to pass to them (e.g. a written list of the
food you want) and the partnerLink is, as previously described, the bit of paper with the restaurant
phone number. BPEL looks at the phone number, dials the restaurant and passes your order to them.
-
So now we have our Hello World BPEL process that passes a string to a printout web service, we need to have
a printout web service that will print the string out for us.
In order to use a web service, it must be defined somewhere. That somewhere is in a WSDL file. The WSDL
file describes how to use the web service (the API to the web service) and also how that web service is
bound. It is possible to split up a WSDL file so that a web service can be described once but implemented
multiple times in lots of different ways but in this simple example we'll just stick to one description -
one implementation.
- as a SOAP/HTTP web service - whereby some implementation would be listening on a specified port and would accept SOAP messages over an HTTP transport.
- as a Java web service - whereby some java class is mapped to the port type and is used directly as an implementation.
Web Service Description (WSDL file)
The Target Namespace
Analogy
(Programming) XML namespaces are like packages in Java. The WSDL messages and port type created in
the WSDL file inherit the XML namespace specified by the targetNamespace attribute.
(Real World) ?
WSDL Messages
WSDL Port Types
Analogy
(Programming) The WSDL port type is like an interface or abstract class. It doesn't specify
any particular implementation for anything, but it does say exactly what can be done, and what goes in
and comes out.
(Real World) The port type is like a description of how to phone up and order food from any
restaurant. The description doesn't specify how the food is cooked or which restaurant to phone, only
what the steps are to phone them and the information they will need.
WSDL Port Type Bindings
WSDL Service
Partner Link Types
The Java Web Service Implementation
-
To deploy your newly written printout web service in B2J, please read the B2J Deployment Tutorial.
If you found this tutorial useful or lacking in any way or if you think there are certain areas which could be better explained or more fully explained please Let Me Know.
