Share via


WSASetService (Windows Sockets) (Compact 2013)

3/26/2014

This function registers or removes from the registry a service instance within one or more name spaces. This function can be used to affect a specific name space provider, all providers associated with a specific name space, or all providers across all name spaces.

Note

WSASetService is not supported by the default DNS/WINS namespace provider (Nspm.dll) in Windows Embedded Compact. However, third parties can implement their own provider and have support for this function if they choose.

Note

This function is supported by the Peer Name Resolution Protocol (PNRP) provider in Windows Embedded Compact.

Syntax

INT WSASetService(
  LPWSAQUERYSET lpqsRegInfo, 
  WSAESETSERVICEOP essOperation, 
  DWORD dwControlFlags
);

Parameters

  • lpqsRegInfo
    [in] Pointer to the service information for registration or deregistration.
  • essOperation
    [in] Enumeration. The following table shows the possible values.

    Value

    Description

    RNRSERVICE_REGISTER

    Registers the service. For Service Access Protocol (SAP), this means sending out a periodic broadcast. This is an no operation instruction (NOP) for the Domain Name System (DNS) name space. For persistent data stores, this means updating the address information.

    RNRSERVICE_DEREGISTER

    Removes the service from the registry. For SAP, this means stop sending out the periodic broadcast. This is an NOP for the DNS name space. For persistent data stores, this means deleting address information.

    RNRSERVICE_DELETE

    Deletes the service from dynamic name and persistent spaces. For services represented by multiple CSADDR_INFO structures (using the SERVICE_MULTIPLE flag), only the supplied address will be deleted and this must match exactly the corresponding CSADDR_INFO structure that was supplied when the service was registered.

  • dwControlFlags
    [in] Description of dwControlFlags is dependent on a specific value. The following table shows this value.

    Flag

    Description

    SERVICE MULTIPLE

    Controls the scope of operation. When clear, service addresses are managed as a group. A registration or removal from the registry invalidates all existing addresses before adding the given address set. When set, the action is only performed on the given address set. A registration does not invalidate existing addresses and a removal from the registry only invalidates the given set of addresses.

    The following table shows the meaning of the combined values for essOperation and dwControlFlag.

    Operation

    Flags

    Service already exists

    Service does not exist

    RNRSERVICE_ REGISTER

    None

    Overwrites the object and uses only addresses specified. The object is REGISTERED.

    Creates a new object. Uses only addresses specified. Object is REGISTERED.

    RNRSERVICE_ REGISTER

    SERVICE_ MULTIPLE

    Updates object and adds new addresses to the existing set. The object is REGISTERED.

    Creates a new object. Uses all addresses specified. Object is REGISTERED.

    RNRSERVICE_ DEREGISTER

    None

    Removes all addresses, but it does not remove the object from the name space. The object is removed from the registry.

    WSASERVICE_ NOT_FOUND

    RNRSERVICE_ DEREGISTER

    SERVICE_ MULTIPLE

    Updates the object and removes only addresses that are specified. It only marks the object as DEREGISTERED if no addresses are present. It does not remove the object from the name space.

    WSASERVICE_ NOT_FOUND

    RNRSERVICE_ DELETE

    None

    Removes the object from the name space.

    WSASERVICE_ NOT_FOUND

    RNRSERVICE_ DELETE

    SERVICE_ MULTIPLE

    Removes only addresses that are specified. It only removes the object from the name space if no addresses remain.

    WSASERVICE_ NOT_FOUND

Return Value

The return value is zero if the operation was successful. If an error occurs, the value SOCKET_ERROR is returned, and a specific error number can be retrieved by calling WSAGetLastError.

The following table shows a list of possible error codes.

Error code

Description

WSAEACCES

The calling routine does not have sufficient privileges to install the service.

WSAEINVAL

One or more required parameters were invalid or missing.

WSANOTINITIALIZED

WiS2_32.dll has not been initialized. The application must first call WSAStartup before calling any Windows Sockets functions.

WSA NOT ENOUGH MEMORY

There was insufficient memory to perform the operation.

WSASERVICE NOT FOUND

No such service is known. The service cannot be found in the specified name space.

Remarks

SERVICE_MULTIPLE lets an application manage its addresses independently. This is useful when the application wants to manage its protocols individually or when the service resides on more than one computer. For instance, when a service uses more than one protocol, it may find that one listening socket aborts but the others remain operational. In this case, the service could remove the aborted address from the registry without affecting the other addresses.

When using SERVICE_MULTIPLE, an application must not let stale addresses remain in the object. This can happen if the application aborts without issuing a DEREGISTER request. When a service registers, it should store its addresses. On its next invocation, the service should explicitly remove these old stale addresses from the registry before registering new addresses.

Service Properties

The following table describes how service property data is represented in a WSAQUERYSET structure. Fields labeled as (Optional) can be supplied with a NULL pointer.

WSAQUERYSET member name

Service property description

dwSize

Must be set to sizeof (WSAQUERYSET). This is a versioning mechanism.

dwOutputFlags

Not applicable and ignored.

LpszServiceInstanceName

The referenced string contains the service instance name.

LpServiceClassId

The globally unique identifier (GUID) corresponding to this service class.

LpVersion

(Optional) Supplies the service instance version number.

LpszComment

(Optional) An optional comment string.

DwNameSpace

See the following table.

LpNSProviderId

See the following table.

LpszContext

(Optional) Specifies the starting point of the query in a hierarchical name space.

DwNumberOfProtocols

Ignored.

LpafpProtocols

Ignored.

LpszQueryString

Ignored.

DwNumberOfCsAddrs

The number of elements in the array of CSADDR_INFO structures referenced by lpcsaBuffer.

LpcsaBuffer

A pointer to an array of CSADDR_INFO structures that contain the addresses on which the service is listening.

LpBlob

(Optional) This is a pointer to a provider-specific entity.

The following table shows how the combination of the dwNameSpace and lpNSProviderId parameters determines that name space providers are affected by this function.

DwNameSpace

lpNSProviderId

Impact

Ignored

Non-NULL

The specified name space provider.

A valid name space identifier

NULL

All name space providers that support the indicated name space.

NS_ALL

NULL

All name space providers.

Notes for Bluetooth

RFCOMM servers call WSASetService to do any of the following tasks:

  • Register service information with Winsock and the SDP driver.
  • Update an SDP record.
  • Delete an SDP record.

Requirements

Header

winsock2.h

Library

Ws2.lib

See Also

Reference

Windows-Specific Extension Functions
WSAGetLastError
WSAStartup