Service Invocation
Once defined in the schema, External Services can be invoked through two distinct channels: Code and Orchestration.
1. Invoking via C# Scripts (Synchronous)
In any C# script (e.g., inside a CustomAction or OnValidate), the IScriptContextBridge automatically injects a Services container property. This container holds instantiated, strongly-typed clients for every service defined in your schema.
// Example: Invoking the raw method requiring a DTO
var dto = new Struktural.Generated.Services.Stripe.Models.ChargeCreateDto
{
Amount = Entity.Total,
Currency = "USD"
};
// Services.{ServiceName}.{EndpointName}(...)
var response = await Services.Stripe.CreateCharge(dto);
if (!response.Success)
{
AddError($"Payment failed: {response.ErrorMessage}");
return;
}
If you configured MappedInputEntity, you can call the generated helper method and simply pass the current Entity:
// Services.{ServiceName}.{EndpointName}From{EntityName}(...)
var response = await Services.Stripe.CreateCustomerFromClient(Entity);
2. Invoking via Workflows (Asynchronous)
For long-running processes where you don't want to block the user interface, invoke services using the CallExternalApi workflow node.
{
"Id": "api_1",
"Type": "CallExternalApi",
"NextNodeId": "node_2",
"Configuration": {
"ServiceName": "Stripe",
"EndpointName": "CreateCustomer",
"PayloadVariable": "Entity"
}
}
PayloadVariable: Indicates which workflow memory variable contains the data to be sent. If you use mapped endpoints, point this to"Entity". If you built a custom JSON structure usingExpressionTransform, point it to that variable (e.g.,"Variables.MyDto").