Compartilhar via


Service object

The Service object represents an individual service on the device and provides access to the properties, methods, and events that are exposed by the service and its content.

A Service object can be retrieved in the following ways: by a zero-based numeric index, by Persistent Unique ID (PUID), or by service type, as shown in the following code.

// Retrieve a service object by index.
var serviceObject = deviceObject.Services[Index];

// Retrieve a service object by PUID.
var serviceObject = deviceObject.Services[PUID];

// Retrieve a service object by service type.
var coolServices = deviceObject.GetServicesByType("{123456678-AAAA-BBBB-CCCC-DDDDEEEEFFFF}");
var serviceObject = coolServices[Index];

Members

The Service object has these types of members:

  • Events
  • Methods
  • Properties

Events

The Service object has these events.

Event Description
onAddChildComplete

Occurs when a Service.AddChild operation is completed.

onGetChildrenByFormatComplete

Occurs when a Service.GetChildrenByFormat operation is completed.

onMethodComplete

Occurs after a service-defined method is completed.

onObjectAdded

Occurs after an object is added to this Service object.

onObjectRemoved

Occurs after an object is removed from this Service object.

onObjectUpdated

Occurs after an object is updated on this Service object.

onRemoveChildComplete

Occurs when a Service.RemoveChild operation is completed.

onServiceEventName

The name of this event is defined by the service. For example, if a service defines an event called MySuperEvent, the event handler property will be onMySuperEvent.

 

Methods

The Service object has these methods.

Method Description
AddChild

Adds a WPDObject, obtained from the Service.CreateNewObject method, as a child of this Service object.

CreateNewObject

Creates and initializes a WPDObject to the specified data format.

GetChildrenByFormat

Returns a collection of the immediate children of this Service object filtered by one or more formats.

Method

Invokes a service-defined method.

RemoveChild

Deletes a child object from this Service object.

 

Properties

The Service object has these properties.

Property Access type Description

AbstractServices

Read-only

Gets a collection of the abstract service GUIDs that this service implements.

Children

Read-only

Gets a collection of all of the immediate children of this Service object.

ServiceProperty

Read/write

Gets or sets a service-defined property of this Service object.

WpdProperty

Read/write

Gets or sets a predefined WPD property for this Service object.

 

Requirements

Minimum supported client

Windows 7 [desktop apps only]

Minimum supported server

Windows Server 2008 R2 [desktop apps only]

See also

About the Service Object

Device Object

WPD Automation Reference

WPDObject