In this recipe, we will identify how to call web services in a sequence from the BPEL process. The sequential web service invocation presents one of the basic workflow concepts. We use this approach when we have several web services in our business process and each of them needs to wait for the previous one to finish.
We need to set up an environment where we can access multiple web services. Since the BPEL processes are also exposed as web services, we can also call another BPEL process in a sequence.
The following steps explain how to call a web service in a sequence from the BPEL process:
BookHotelSvc
: This web reference helps to gather the hotel names that have available rooms in a selected periodRoomPriceSvc
: This web reference queries the room price in the hotelThe SOA composite or SCA (Service Composition Architecture) outlook is as shown in the following screenshot:
In the SCA we can see the interconnection between the BPEL processes, how the BPEL process is exposed as web service, and which web services the BPEL process is referencing. We describe here the SCA from the BPEL process point of view; however, other components, such as human tasks, mediator components, business rules, and various adapters fit in.
<sequence name = "Hotels_And_Prices"> <assign name = "AssignAvailHotels"> <copy> <from>xp20:current-dateTime()</from> <to>$AvailableHotels_availableHotels_InputVariable.parameters/ns1:from</to> </copy> <copy> <from>xp20:current-dateTime()</from> <to>$AvailableHotels_availableHotels_InputVariable.parameters/ns1:to</to> </copy> </assign> <invoke name = "AvailableHotels" bpelx:invokeAsDetail = "no" partnerLink = "BookHotelSvc" portType = "ns1:HotelBooking" operation = "availableHotels" inputVariable = "AvailableHotels_availableHotels_InputVariable" outputVariable = "AvailableHotels_availableHotels_OutputVariable"/> <assign name = "AssignRoomPrice"> <copy> <from>$inputVariable.payload/client:input</from> <to>$GetRoomPrice_getPrice_InputVariable.parameters</to> </copy> </assign> <invoke name = "GetRoomPrice" bpelx:invokeAsDetail = "no" partnerLink = "RoomPriceSvc" portType = "ns2:RoomPriceServicePortType" operation = "getPrice" inputVariable = "GetRoomPrice_getPrice_InputVariable" outputVariable = "GetRoomPrice_getPrice_OutputVariable"/> </sequence>
In cases when the calls to multiple web services are dependent, we use the sequential execution of web services. Such a case can, for example, be a loan approval. Suppose we have a web service for the loan approval and a web service for the money transfer. It is obvious that money cannot be transferred before the loan is approved.
The sequence execution of web services in the BPEL process is achieved through the sequence activity. We used the sequence activity in this recipe in order to ensure that we get the price of the hotel room, only if the room is available.