Cert++
Close

Service callbacks for building requests and parsing responses

Key Takeaway

createRequest builds the request from your Service.call() arguments. parseResponse turns the reply into result.object. For an HTTP service, the framework does not call your own execute callback unless the callback object sets executeOverride: true.

B2C Commerce code calls an external web service through the service framework. When you create a service instance, you pass in an object that holds callback functions you write. The framework runs those callbacks during the call. The createRequest callback turns the arguments you give to Service.call() into the real request. The parseResponse callback turns the raw reply into the object your code gets back. Which other callbacks you must write depends on the service type.

How to call a service
  1. Configure the service in Business Manager. There you give the service an ID and pick its service type: HTTP, HTTP Form, FTP, SFTP, SOAP or Generic.
  2. Create a service instance with dw.svc.LocalServiceRegistry.createService(). Pass two arguments: the service ID and the callback object, which holds your callback functions.
  3. Run the instance by calling Service.call() with any arguments the request needs.
  4. Check the dw.svc.Result that comes back.

A service instance is a single-use object, so create a new instance for each call.

B2C Commerce Developer Study Guide

Checklist progress

0/237Learned

Prepare for the Exam

Play Today's Certle

Study Community

Ask questions and get the latest info from other B2C Commerce Developer studiers.