Designer 10.5 | webMethods Mobile Development | Adding Services to a Mobile Project | Adding Virtual Services
 
Adding Virtual Services
Virtual Services can be considered as an abstraction layer on top of services. They allow you to load data from different RESTful services and to map this data to EML entities (Entity Modeling Language).
They introduce the concept of different contexts in EML entities for @JsonProperty mappings as shown in the following example:
entity CaseType {
// default expression
@JsonProperty(expression="candybarType.caseAppName")
// contextual expression when loading from AgileApps source
@JsonProperty([AgileApps] expression="content")
String caseAppName;
}
By mapping different services and their JSON responses to one EML entity, you can work with entities in code or user interface bindings without checking context or which service was used to load the data.
Virtual Services can be useful
*If you want to support different API versions in one project.
*If you want to support different APIs for the same data to be displayed (e.g., to load and display data from different sources).
Important:
You must create a RESTful service before creating a Virtual Service. For more information, see Adding RESTful Services.
*To add a Virtual Service
1. Ensure the mobile project is open in the Outline Editor. For instructions, see Displaying a Mobile Project in the Outline Editor.
2. In the Model section of the Outline Editor, expand the project so that you view the Services container node.
If the model does not have a Services container node, add one by right-clicking the root application and selecting New Child > Services.
3. Right-click the Services node, and select New Child > Virtual Service.
4. Right-click the Virtual Service node, and select New Child > RestMethodDelegate.
Note:
You must add at least two REST methods.
5. Select one of the REST methods nodes, and in the Properties section of the Outline Editor set the properties for it as follows:
*For Invoke When, specify when the method should be called. This value must be unique within a Virtual Service.
Note:
You can set Invoke When in code using the following snippet:
AbstractVirtualOperation.CONTEXT.setContextName (
"myInvokeWhen");
InvokeWhen must be equivalent to the contexts specified for the entity.
*For Rest Method, the entry is populated and corresponds to the name of the REST method node. If you select a different REST method from the menu, the name of the REST method node changes accordingly.
6. Repeat this step for the other REST method node(s).
Tip:
To update the Java classes that Mobile Development generates for the project so that your changes are represented in the generated sources, save the project and regenerate sources. For instructions, see Generating Sources for a Mobile Project.
Related Topics