Creating a New Local ServiceThis tutorial walks you through creating a new local service for your application. In this example, we create a very simple Python service that takes no arguments and returns a string. We create a Page to display the string and we put a button on the HomePage to call the service.Within an ActiveGrid Application, a service is anything that has one or more defined operations that the application can run. Services might be defined in custom code (Python or PHP) files within your application or they might be web services available on the Internet. ActiveGrid Applications use a Service Definition to access all services.The Service Definition file specifies input and output messages for all the Services in the application. ActiveGrid bases the Service Definition file on an industry standard, the Web Services Definition Language (WSDL) document. Service Definition files end in the .wsdl suffix.Your Python or PHP code file represents a service that is available to the application. Functions or methods within your code file represent operations that the application can call. For each service operation, the Service Definition file must define the following:
• An Input Message that specifies the input parameters for that operation. For each input parameter the operation takes, the Input Message defines a Message Part.
• Each operation has an Output Message that contains a Message Part specifying the data that operation returns.
1.
2. Fig. 1 Create a New Project
4. The Page Settings screen appears. Type in the following settings:
• In the Title field, type:
• In the Footer field, type:
5.
6.
7. In the Name field, type:
8. Click Finish.For this simple service call application, we need two Pages. The first Page contains a button that launches the custom service. The second Page displays the result of the service call.Create the Pages:
1. If it is not already open, double-click on the Page Flow, LocalService.bpel file in the Project Panel.
2. Right-click in the Page Flow Editor and, from the Insert Page menu select the Custom... option. Name the Page requestPage and accept the defaults for the other settings.
3. In the same way, insert another custom Page, but this time, name the Page responsePage, again accepting the defaults for the other settings.Before we can add the submit button to the requestPage, we need to define an Action for it in the underlying Page Flow (.bpel) file.
2. From Insert Action select the Call Custom Code... option. This launches the Call Custom Code Wizard.
3. In the Action Source Page screen, select requestPage and then click Next. The Custom Code Details screen appears.
4. In the Action Name field, type in:
5.
6. Click Finish.
7. Back in the Custom Code Details screen, click the New... button for the Function Name field. This launches the Service Operation Wizard.
8. In the Operation Name field, type:
9.
10. Click the Add button to add a new message part. For the name of the message part, type in sayHiRequest and for the type, select xs:string.Fig. 3 Add an Input Message
11.
12. On the Output Message screen click Add and add a new message part. For the name of the message part, type in sayHiResponse and for the type, select xs:string.Fig. 4 Add an Output Message
13. Click Next.
14.
15. Back on the Custom Code Details screen, in the After function go to Page field, select responsePage from the drop-down menu (Figure 5).Fig. 5 Custom Code Details
16. Click FinishThe wizard generates a python skeleton function for you in a file called myService.py. The python skeleton function takes an argument (called sayHiRequest) and returns a value (sayHiResponse). The wizard also generates the corresponding service definition for you in the myService.wsdl file.
1. In the Project Panel, double-click on the Python file, myService.py, to open the skeleton Python file (.py) you created.Fig. 6 The Finished Python CodeNext we complete the skeleton process by editing the Begin Action to point at the requestPage.To finish up the skeleton process, we point the Begin Action at the requestPage and delete the Home Page:
1.
2. The Begin Action now has an arrow pointing to the requestPage.
3. Now we can delete the default Home Page. Right-click on the HomePage Page and select Delete from the resulting pop-up menu.Fig. 7 Finished Skeleton ProcessThe skeleton of the Page Flow is complete with this step. We have a request Page that contains an Action that loads the response Page. The next step is to build a Page Message for the responsePage.Next, we create a place in the responsePage message to store the output from the Python code.
1. In the Project Panel, double-click on the responsePage.xform file. The file opens in the Page Editor.
2. The Insert Message Part screen appears.
3. Click the Name field and type in:
4. Click the Service Call radio button.
5. Fig. 9 Insert Message Part
7. Click OK.Fig. 10 The pythonOutput Message Part
Add the Output Field to the responsePage to Show the Service Results
1. If it’s not already open double-click to open the responsePage.xform file.
2. In the Page Editor, right-click on the Page:responsePage icon and select Insert Group... > Bordered Group.
3. A Bordered Group appears on the Page. Next, right-click on the Bordered Group icon and select the Insert Output Field… > Plain Text Output option from the resulting menu. The Pick a Reference screen appears.
4. When you use a wizard to create a predefined Action, the wizard sets all the local (Action) variables for you. Because we created a custom Action, to call our local service, we need to do some of this work manually.Open the SayHi Action in the Custom Action Editor
1. Double-click on the process file, simpleService.bpel, to open the process (.bpel) file for the application.
2. In the Process Editor, right-click on the SayHi Action and select the Customize Action... option. This opens the SayHi Action in the Custom Action Editor (Figure 11).
• sayHiRequestMsgVar: The wizard created this variable to represent the input message we defined for our service operation.
• sayHiResponseMsgVar: The wizard created this variable to represent the output message we defined for our service.
• responsePageRequestMsgVar: The wizard created this variable to represent the backing message for the Page we’re invoking.
• The myService sayHi invoke is a call to our custom operation in the local service we wrote.
• We need to populate the responsePageRequestMsgVar variable. That is the variable the server uses to build the backing Page Message for the responsePage.Set the Input Variable for the responseXForm Invocation
1. In the Custom Action Editor, right-click on the service Invoke (sayHiResponseMsgVar = myService:sayHi(sayHiRequestMsgVar)) and select Add Set... from the menu (Figure 12).Fig. 12 Insert a “Set”The BPEL Set screen appears.
2. Fig. 13 Click the Top XPath ButtonThe Select an XPath dialog appears.Fig. 14 Select XPath
4. Click OK.
5. In the bottom half of the BPEL Set screen, under XPath Expression, click the XPath Ref… button (Figure 15).Fig. 15 Click the Bottom XPath ButtonThe Select an XPath dialog again appears.Fig. 16 Set the Variable
7. Click OK.Fig. 17 The Completed Set Details ScreenFig. 18 Custom Action Editor with SetFig. 19 The Running ProcessFig. 20 The Hello Message
ActiveGrid |
ActiveGrid Studio Tutorial |
Version 2.0 |