Advanced Options to Invoke Webservices
From Business Process Management, BPM and Workflow Automation Wiki | BizAgi BPMS
<keywords content="keywords"> soa, interface, interfaces, web service, web services, webservice, webservices, soa interface </keywords>
Contents |
Advanced Options to Invoke Webservices
Preferably, a web service should always be modeled in a Service Task and using the basic options of the Interface Wizard. For some exceptional cases, if this is not possible, Bizagi also has other ways of invoking a Web Service , which are explained in this article, including the Interface Wizard advanced options.
From a Business Rule
In the next example, a Web Service has a web method that receives and returns simple data types (integer, string, boolean, etc.):
In a vacation request process, a Web Service is invoked at the beggining of the process (the expression that is about to be created in this example is not included by default in the Vacation Leave Request template that comes with the Bizagi installer, we modified the process for teaching purposes).
1. Open the process for expression edition and creation. Right click on the Activity Actions (Events) link, in the fourth step of the Wizard View (Business Rules).
2. Click on the Activity that is going to be modified (in this case, the Automatic Activity Verify Available Vacation Days).
3. Click on On Enter or On Exit, depending on when the expression is going to be excecuted. On the bottom of the Activity Actions Window, click the green plus sign that activates and select Expression.
4. Once the Expression Window to create a new Expression is opened, type the Name, Display Name and Description for the expression.
5. Create a variable for the web services response by right clicking the Start button and choose Variable Declaration.
6. In the Variable Declaration window, click Add, select integer (int) in the Type column , type a Name and set the initial value to zero (0). Click on OK.
7. Right click over the vertical arrow and select Add Web Service.
8. In the Web Service - Description window write a description and click OK.
9. Double click the Web Service module to open the Web Service Invocation window.
10. Enter the web service location and click Next.
11. Select the method from the list and click Next.
12. If the chosen method requires input parameters they should be entered here. Select the parameter to be set and click the Set Value button. In the Set Value window an XPath expression is used to find the applicant's username. Click OK and then Next.
13. To finalize the web service configuration select the variable where the result will be stored and click Next.
14. The response from the web service is used to set a process attribute. Right click on the vertical arrow after the Web Service module and select Add Assignment.
Write a description for the assignment and click OK. Double click on the Assignment module and click the Add button to include one. In the left side of the assignment select the destination attribute by choosing the option select attribute (for this example is VacationRequest.DaysAvailableNumber). For the right side, first select Expression and then write the variable that has the web service response (DaysNumber).
15. Finally, click OK on every window to close them and save the changes. In the Activity Actions window also click OK.
As a SOA Interface
This is the best way to invoke a web service if the web methods receives and returns an XML document or a string representation of an XML document, if the basic configuration cannot be used.
In the same vacation request process, the last three payroll payments for an applicant are required in the Approve Vacation Request activity. The information is in an external system that requires the following web service to be invoked for this consultation:
For this interface an XSD file is provided that defines the structure of the input and output messages. In order to find additional information about how to invoke Web Services with custom data types, please refer to this Article. The xmlInput must comply with this structure:
And the following for the UserPayrollResult:
As can be seen from the first schema, the applicant's username needs to be sent. This information can be obtained from Bizagi in an XML document but not with the structure the web service requires. It is therefore necessary to transform the XML using an XSL/XSLT. Also the information returned in an XML format can be saved in Bizagi but it has to be transformed into a structure Bizagi understands. It is necessary to use another XSL/XSLT. The following steps are taken to achieve this, but first is important to understand the data model, so the retrieving and saving of data can be done. This is the data model to be used:
1. Open the process for edition. Right click on the Activity Actions (Events) link, in the fourth step of the Wizard.
2. Click on the Activity and then click On Exit.
3. On the bottom of the Activity Actions Window, click the green plus sign that activates and select Interface.
4. The interfaces wizard will be launched.
Note: For this shown configuration in the interfaces wizard, we first select SOAP as the service type:
|
Then, type the web service’s URL, and click on the Go button. The system has a Default option that can be changed for a previously defined system.
5. . When the Resolve button is clicked, the interface methods appear. Select the one to be used and click Next.
Also when a method is selected, a System and Interface Name is suggested. This values can be changed if desired.
6. The interface expects the petitioner's username in an XML document. This can be obtain using XPath, XSD and XSL. On the next window click on Select Bizagi XPath to Retrieve data, a frame opens, expand the attributes for VacationRequest and select Petitioner by double-clicking it, this would be the "context entity".
7. Then click on Define Schema if XML or complex type expected. A little window opens to select the attribute(s) that would be send to the interface. For this reason, for this example, only the userName attribute is checked. Click OK when finish selecting attributes.
It is possible to see the XSD by click View schema, in this window it can also be edited directly. Is also useful to copy it and use it to build the transformation that follows.
Click Next.
8. Now click on Define XSL transformation, this will open a window to find and select and XSLT file in the computer's file system. An XSLT file can be written using Altova XMLSpy or generate it with Altova MapForce, find them here: http://www.altova.com/
Once the XSLT is uploaded, it can be view or change by clicking on View XSL.
Click Next to continue.
9. To configure the output parameters, since the interface returns an XML Document, click on Upload XSD validator or transformation if needed, then click Add a XSL to transform XML (complex type) response. In the window that opens, find and select a XSLT file from the file system. When done, click Next.
10. For error handling select in Error invoking Web Service - Action, Throw Exception.
Alert: XML has a special set of characters that cannot be used in normal text, like the strings between tags. These characters are:
If is necessary to use this characters use a CDATA section (see getEntities). For example: Instead of <Company>Johnson & Johnson</Company> use <Company><![CDATA[Johnson & Johnson]]></Company> |
From a Button in a Form
It is also possible to invoke a web service when the user wants in a manual activity. This is accomplished by including a button in the activity's form. Then, in the render Properties, find Interface click in the value cell and select Add/Edit. This would open the Interface Wizard where the interface can be configured as explain before.
Note: If from a Bizagi project a Java web service is necessary used, consider if the web service implementation's definition has mapped its access so its invocation has the ?wsdl or .wsdl termination. Is advisable to have knowledge about the target web service's specification, or contact someone who does. |
Advanced and Related Topics
- To learn more about Expressions, click here.
- Read more about Service Tasks in this article.
- Asynchronous Service Tasks or Activities are explained in this page.
- If other functions are needed to manipulate XMLs in rules, read this.
- Read more about how to invoke Web Services using the wizard in this Article.
<comments />