Call External Services
This task describes how to configure a virtual service to call external services.
Note:
- This task is part of a higher-level task. For details, see Modify Virtual Service Behavior.
-
Service call activity is supported for:
-
SOAP services over HTTP or JMS
-
Binary over HTTP, JMS, WebSphere, or File System
-
XML services over HTTP, JMS, WebSphere MQ, or Filesystem
-
REST services
-
Fixed Length messages over TCP
-
CSV over File System and WebSphere
-
Create service call activity by importing a service description
- In the Data Model Editor, select the operation from which you want to call the external service.
-
To import a new service description, click Activity > Import Activities. Enter the path to the WSDL for a SOAP service, to the XML schema for an XML service, or to the OpenAPI (Swagger) file for a REST service.
Note: If you are importing an XML service that requires HTTP authentication, you must add the user name and password to the Service Virtualization credential store.
- The Identify Name you enter in the credential store must be SCA:<name of called activity>.
- Alternatively, you can create a global Identity Name SCA which is used if no specific identity exists in the credential store.
For user interface details, see Edit Credential Store Dialog Box.
- For a SOAP service: In the Select Service Operation dialog box, select an activity to add, or import the service description document for use at a later time. For user interface details, see Select Service Operation Dialog Box.
-
For an XML over HTTP service: In the Service Properties dialog boxes:
- Select message elements for input and output messages.
- Enter the URL on which the real service runs.
- To add a new activity to your data model, select an operation, click Activity again, and select an activity. Choose whether to add it before or after the response.
Create service call activity by importing messages
- In the Data Model Editor, click Activity > Import Activities.
- Select I don't have a service description.
- Select a service protocol.
- Enter the service properties. For details, see Service Properties Page.
- In the Select Service Operation dialog box, select Do not add an activity now.
-
Import messages into the newly created service call activity.
- Select Activity > SCA Description > Learn Schema from Messages.
- Select messages to import. For details, see Learn Schema Dialog Box.
New activities are created based on the imported messages.
- To add a new activity to your data model, select an operation, click Activity again, and select an activity. Choose whether to add it before or after the response.
Work with service call activity in the Data Model
After you add the service call activity (SCA) to an operation in your data model, you can see it in each rule in the operation. The following options are then available:
Task | Details |
---|---|
Edit properties for a SCA | Right-click the activity's column header and click Activity Properties. For user interface details, see Activity Properties Dialog Box. |
Edit protocol metadata | To add, enable, or disable protocol headers, right-click the activity's column header and click Activity Service Description Editor. Then click Edit for request or response metadata. For user interface details, see Edit Metadata Dialog Box. |
Remove SCA from a rule | Right-click the column header and click Remove Activity. |
Enable or disable SCA in a rule | Click the on/off icon in the rule's header. |
Handle connection failure |
To handle connection failure, define a response for the virtual service to return if the service call activity cannot connect to the external service.
|
Tip:
- You can use the Copy from function on any service call request column, or virtual service response column. Select the Copy from function. The columns that you can use as a source are highlighted. Click the desired source column.
- Use the Row Detail dialog box for easier configuration of the service call activity. For details, see Row Detail Dialog Box.
Override service call activity properties
Some service call activities support overriding the URL or Destination you have set in the Activity Properties. This allows you to dynamically change the service call activity target.
Note:
-
Setting destination override is straightforward for protocols like REST, where you just specify a new base URL. For other protocols, to see the correct format of the destination override value, you can check the address attribute of the
virtualEndpoint
element in a *.vs file of any virtual service based on that protocol. -
Destination override can be set via a script in a scripted rule. The following example shows how the base URL of a service call activity number 4, called
TestCall
can be set to http://example.com/test in a C# scripted rule:sv.Activities.Activity4_TestCall.Request.Overrides.RequestDestination = "http://example.com/test";
To override service call activity properties:
- In the Data Model Editor, right-click the upper-most header of Service Call Activity.
-
In the Activity Service Description Editor, click Edit to open the Request metadata editor. For user interface details, see Edit Metadata Dialog Box.
-
Enable the Overrides section, and then enable the RequestDestination override.
-
After the override is enabled, new fields are available in the Data Model Editor where you can override the destination. The same can be also performed via the scripted rule.