# Class ServiceDefinition

- [TopLevel.Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)
  - [dw.svc.ServiceDefinition](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.svc.ServiceDefinition.md)

Base class of Service Definitions.

A service definition represents configuration that is shared across all [Service](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.svc.Service.md) instances.

**Deprecated:**

:::warning
This class is only used with the deprecated [ServiceRegistry](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.svc.ServiceRegistry.md). Use the [LocalServiceRegistry](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.svc.LocalServiceRegistry.md)
instead, which allows configuration on the [Service](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.svc.Service.md) directly.
:::

**API Version:**

:::note
No longer available as of version 19.10.
:::

## All Known Subclasses

[FTPServiceDefinition](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.svc.FTPServiceDefinition.md), [HTTPFormServiceDefinition](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.svc.HTTPFormServiceDefinition.md), [HTTPServiceDefinition](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.svc.HTTPServiceDefinition.md), [SOAPServiceDefinition](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.svc.SOAPServiceDefinition.md)

## Property Summary

| Property                                                                                                                                      | Description                                                                              |
| --------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| [configuration](#configuration): [ServiceConfig](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.svc.ServiceConfig.md) `(read-only)` | Returns the Service Configuration stored in the database.                                |
| [mock](#mock): [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)                                           | Returns the status of whether mock mode is enabled for all instances of this definition. |
| [serviceName](#servicename): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md) `(read-only)`                 | Returns the name of this service.                                                        |
| [throwOnError](#throwonerror): [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)                           | Returns the status of whether the shared throwOnError flag is set.                       |

## Constructor Summary

This class does not have a constructor, so you cannot create it directly.

## Method Summary

| Method                                                                                                                                                                                             | Description                                                                              |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| [configure](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.svc.ServiceDefinition.md#configureobject)([Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)) | Register a callback to handle custom portions of the service.                            |
| [getConfiguration](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.svc.ServiceDefinition.md#getconfiguration)()                                                                           | Returns the Service Configuration stored in the database.                                |
| [getServiceName](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.svc.ServiceDefinition.md#getservicename)()                                                                               | Returns the name of this service.                                                        |
| [isMock](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.svc.ServiceDefinition.md#ismock)()                                                                                               | Returns the status of whether mock mode is enabled for all instances of this definition. |
| [isThrowOnError](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.svc.ServiceDefinition.md#isthrowonerror)()                                                                               | Returns the status of whether the shared throwOnError flag is set.                       |
| [setMock](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.svc.ServiceDefinition.md#setmock)()                                                                                             | Sets the mock mode for all Service instances that use this definition.                   |
| [setThrowOnError](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.svc.ServiceDefinition.md#setthrowonerror)()                                                                             | Sets the throwOnError flag to true for all Service instances that use this definition.   |

### Methods inherited from class Object

[assign](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#assignobject-object), [create](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#createobject), [create](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#createobject-object), [defineProperties](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#definepropertiesobject-object), [defineProperty](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#definepropertyobject-object-object), [entries](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#entriesobject), [freeze](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#freezeobject), [fromEntries](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#fromentriesiterable), [getOwnPropertyDescriptor](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getownpropertydescriptorobject-object), [getOwnPropertyNames](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getownpropertynamesobject), [getOwnPropertySymbols](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getownpropertysymbolsobject), [getPrototypeOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getprototypeofobject), [hasOwnProperty](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#hasownpropertystring), [is](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isobject-object), [isExtensible](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isextensibleobject), [isFrozen](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isfrozenobject), [isPrototypeOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isprototypeofobject), [isSealed](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#issealedobject), [keys](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#keysobject), [preventExtensions](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#preventextensionsobject), [propertyIsEnumerable](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#propertyisenumerablestring), [seal](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#sealobject), [setPrototypeOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#setprototypeofobject-object), [toLocaleString](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#tolocalestring), [toString](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#tostring), [valueOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#valueof), [values](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#valuesobject)

## Property Details

### configuration

- configuration: [ServiceConfig](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.svc.ServiceConfig.md) `(read-only)`
  - : Returns the Service Configuration stored in the database.

***

### mock

- mock: [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)
  - : Returns the status of whether mock mode is enabled for all instances of this definition.

***

### serviceName

- serviceName: [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md) `(read-only)`
  - : Returns the name of this service.

***

### throwOnError

- throwOnError: [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)
  - : Returns the status of whether the shared throwOnError flag is set.

***

## Method Details

### configure(Object)

- configure(config: [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)): [ServiceDefinition](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.svc.ServiceDefinition.md)
  - : Register a callback to handle custom portions of the service.

    This callback may declare multiple methods:

    ```
    {
      initServiceClient: function() {
          // Create and return the internal service client object.
          // This is usually optional, except in the case of SOAP services.
      },

      // svc is the call-specific Service instance. For example, it may be an HTTPService or FTPService.
      // params are the arguments passed to the call method (if any).
      createRequest: function(svc:Service, params) {
           // Perform any required call-time configuration.
           // Optionally return a Service-specific object
      },

      // svc is the call-specific Service instance.
      // arg is the output of createRequest.
      execute: function(svc:Service, arg:Object) {
           // Execute the service call and return a result
           // This method is not used by default for HTTP-related services unless executeOverride is set.
      },

      // Use the execute function if it is present. This is only required to use the functionality with HTTP services.
      executeOverride: true,

      // svc is the call-specific Service instance.
      // response is the output of execute.
      parseResponse: function(svc:Service, response: Object) {
           // Process the response object as needed.
           // The return value of this method will be the return value of the outer call method.
      },

      // svc is the call-specific Service instance.
      // arg is the output of createRequest.
      mockCall: function(svc:Service, arg:Object) {
           // This method takes the place of the 'execute' phase when mocking is enabled.
           // Note initServiceClient, createRequest, and parseResponse still invoked.
      },

      // svc is the call-specific Service instance.
      // params are the arguments passed to the call method (if any).
      mockFull: function(svc:Service, params) {
           // This method takes the place of the entire service call when mocking is enabled.
           // No other callbacks are invoked. The output of this method becomes the output of call.
      }

    }
    ```

    **Parameters:**

    - config - Callback object.

    **Returns:**

    - this

***

### getConfiguration()

- getConfiguration(): [ServiceConfig](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.svc.ServiceConfig.md)
  - : Returns the Service Configuration stored in the database.

    **Returns:**

    - Service Configuration.

***

### getServiceName()

- getServiceName(): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)
  - : Returns the name of this service.

    **Returns:**

    - Service name.

***

### isMock()

- isMock(): [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)
  - : Returns the status of whether mock mode is enabled for all instances of this definition.

    **Returns:**

    - true for mock mode, false otherwise.

***

### isThrowOnError()

- isThrowOnError(): [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)
  - : Returns the status of whether the shared throwOnError flag is set.

    **Returns:**

    - throwOnError flag.

***

### setMock()

- setMock(): [ServiceDefinition](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.svc.ServiceDefinition.md)
  - : Sets the mock mode for all Service instances that use this definition.

    **Returns:**

    - this Service Definition.

***

### setThrowOnError()

- setThrowOnError(): [ServiceDefinition](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.svc.ServiceDefinition.md)
  - : Sets the throwOnError flag to true for all Service instances that use this definition.

    **Returns:**

    - this Service Definition.

***
