IWSDDeviceHost::AddDynamicService method

Registers a service object for incoming requests, but does not add the service to the device host metadata. This is used for transient (dynamic) services.


HRESULT AddDynamicService(
  [in]                 LPCWSTR        pszServiceId,
  [in, optional]       LPCWSTR        pszEndpointAddress,
  [in, optional] const WSD_PORT_TYPE  *pPortType,
  [in, optional] const WSDXML_NAME    *pPortName,
  [in, optional] const WSDXML_ELEMENT *pAny,
  [in, optional]       IUnknown       *pService


pszServiceId [in]

The ID for the dynamic service. The service ID must be distinct from all the service IDs in the service host metadata and from any other registered dynamic service. The pszServiceId must be a URI.

pszEndpointAddress [in, optional]

An optional URI to use as the endpoint address for this service. If none is specified, the device host will assume the service should be available on all local transport addresses.

pPortType [in, optional]

Reference to a WSD_PORT_TYPE structure that specifies the port type. May be NULL. Specify only one of pPortType and pPortName.

pPortName [in, optional]

Reference to a WSDXML_NAME structure that specifies the type of the service, with associating the service with a specified port. Specify only one of pPortType and pPortName.

pAny [in, optional]

Optional reference to an extensible section to be included in the dynamic service metadata.

pService [in, optional]

Optional reference to a host service object to register.

Return value

Possible return values include, but are not limited to, the following:

Return codeDescription

Method completed successfully.


pszServiceId is NULL.


The length in characters of pszServiceId or pszEndpointAddress exceeds WSD_MAX_TEXT_LENGTH (8192), or both pPortType and pPortName are specified.


The method failed. It may have failed because the host has not been initialized, or the service specified by pszServiceId could not be found. Call Init to initialize a device host.


Insufficient memory to complete the operation.



When this method is called, the device adds a reference to the service object and calls its methods in response to request messages addressed to the service. Call the RemoveDynamicService method on the device host to release its reference to the service and stop calling methods on the service.


Minimum supported client

Windows Vista [desktop apps only]

Minimum supported server

Windows Server 2008 [desktop apps only]


WsdHost.h (include Wsdapi.h)





See also




Community Additions