Creating and calling a service instance with LocalServiceRegistry
Key Takeaway
To call a configured web service, call the static LocalServiceRegistry.createService method with the service's Business Manager ID and a callbacks object to get a Service instance. Then run it with call(), which passes its arguments to your createRequest callback.
LocalServiceRegistry is the dw.svc class that B2C Commerce scripts use to get a Service object for calling an external web service, such as an HTTP API or an FTP server. You define the service in Business Manager. Your script passes the service ID and your callback functions to createService, and then runs the request with call(). The service framework runs your callbacks in a set order and enforces the rate limit and circuit breaker you configured.
The Business Manager records
Each web service needs three Business Manager records. You create them under "Administration > Operations > Services".
| Record | What it holds |
|---|---|
| Service configuration | Service ID, service type, the "Enabled" flag, "Service Mode" (Live or Mocked), and links to the profile and credential |
| Service profile | Timeout, rate limit and circuit breaker |
| Service credential | URL, plus a username and password for basic authentication |
Different services with similar needs can share one profile. The profile timeout applies to each connection and each read, not to the whole call.
A service profile has a 5000 ms timeout. A call takes 4 seconds to connect and then reads data twice, and each read takes 4 seconds. The whole call takes about 13 seconds, but the call does not time out, because no single connection or read took longer than 5000 ms.