Export (0) Print
Expand All
Expand Minimize

WSASetService function

The WSASetService function registers or removes from the registry a service instance within one or more namespaces.

Syntax


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

Parameters

lpqsRegInfo [in]

A pointer to the service information for registration or deregistration.

essOperation [in]

A value that determines that operation requested. This parameter can be one of the values from the WSAESETSERVICEOP enumeration type defined in the Winsock2.h header file.

ValueMeaning
RNRSERVICE_REGISTER

Register the service. For SAP, this means sending out a periodic broadcast. This is an NOP for the DNS namespace. For persistent data stores, this means updating the address information.

RNRSERVICE_DEREGISTER

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

RNRSERVICE_DELETE

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

 

dwControlFlags [in]

Service install flags value that further controls the operation performed of the WSASetServicefunction. The possible values for this parameter are defined in the Winsock2.h header file.

FlagMeaning
SERVICE_MULTIPLE

Controls scope of operation. When this flag is not set, service addresses are managed as a group. A register 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 register does not invalidate existing addresses and a removal from the registry only invalidates the given set of addresses.

 

Return value

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

Error codeMeaning
WSAEACCES

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

WSAEINVAL

One or more required parameters were invalid or missing.

WSANOTINITIALISED

The Ws2_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.

 

Remarks

The WSASetService function can be used to affect a specific namespace provider, all providers associated with a specific namespace, or all providers across all namespaces.

The available values for essOperation and dwControlFlags combine to control operation of the WSASetService function as shown in the following table.

OperationFlagsService already existsService does not exist
RNRSERVICE_REGISTERNoneOverwrites the object. Uses only addresses specified. The object is REGISTERED.Creates a new object. Uses only addresses specified. Object is REGISTERED.
RNRSERVICE_REGISTERSERVICE_MULTIPLEUpdates the object. Adds new addresses to the existing set. The object is REGISTERED.Creates a new object. Uses all addresses specified. Object is REGISTERED.
RNRSERVICE_DEREGISTERNoneRemoves all addresses, but does not remove the object from the namespace. The object is removed from the registry.WSASERVICE_NOT_FOUND
RNRSERVICE_DEREGISTERSERVICE_MULTIPLEUpdates the object. Removes only addresses that are specified. Only marks the object as DEREGISTERED if no addresses are present. Does not remove the object from the namespace.WSASERVICE_NOT_FOUND
RNRSERVICE_DELETENoneRemoves the object from the namespace.WSASERVICE_NOT_FOUND
RNRSERVICE_DELETESERVICE_MULTIPLERemoves only addresses that are specified. Only removes object from the namespace if no addresses remain.WSASERVICE_NOT_FOUND

 

Publishing services to directories, such as Active Directory Services, is restricted based on access control lists (ACLs). For more information, see Security Issues for Service Publication.

When the dwControlFlags parameter is set to SERVICE_MULTIPLE, an application can 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 other sockets remain operational. In this case, the service could remove the aborted address from the registry without affecting the other addresses.

When the dwControlFlags parameter is set to 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.

Note  If ANSI character strings are used, there is a chance that the WSAQUERYSET data in lpqsRegInfo may not contain any results after this function returns. This is because the ANSI version of this method, WSASetServiceA, converts the ANSI data in WSAQUERYSET to Unicode internally, but does not convert the results back to ANSI. This primarily impacts transports that return a "service record handle" used to uniquely identify a record. To work around this issue, applications should use Unicode string data in WSAQUERYSET when calling this function.

Service Properties

The following table describes how service property data is represented in a WSAQUERYSET structure. Fields labeled as (Optional) can contain a null pointer.

WSAQUERYSET memberService property description
dwSizeMust be set to sizeof (WSAQUERYSET). This is a versioning mechanism.
dwOutputFlagsNot applicable and ignored.
lpszServiceInstanceNameReferenced string contains the service instance name.
lpServiceClassIdThe GUID corresponding to this service class.
lpVersion(Optional) Supplies service instance version number.
lpszComment(Optional) An optional comment string.
dwNameSpaceSee table that follows.
lpNSProviderIdSee table that follows.
lpszContext(Optional) Specifies the starting point of the query in a hierarchical namespace.
dwNumberOfProtocolsIgnored.
lpafpProtocolsIgnored.
lpszQueryStringIgnored.
dwNumberOfCsAddrsThe number of elements in the array of CSADDR_INFO structures referenced by lpcsaBuffer.
lpcsaBufferA pointer to an array of CSADDR_INFO structures that contain the address(es) that the service is listening on.
lpBlob(Optional) This is a pointer to a provider-specific entity.

 

As illustrated in the following, the combination of the dwNameSpace and lpNSProviderId members determine that namespace providers are affected by this function.

dwNameSpacelpNSProviderIdScope of impact
IgnoredNon-nullThe specified name-space provider.
A valid name- space identifierNullAll name-space providers that support the indicated namespace.
NS_ALLNullAll name-space providers.

 

Windows Phone 8: This API is supported.

Requirements

Minimum supported client

Windows Vista [desktop apps only]

Minimum supported server

Windows Server 2003 [desktop apps only]

Minimum supported phone

Windows Phone 8

Header

Winsock2.h

Library

Ws2_32.lib

DLL

Ws2_32.dll

Unicode and ANSI names

WSASetServiceW (Unicode) and WSASetServiceA (ANSI)

See also

Bluetooth and WSASetService
Winsock Reference
Winsock Functions
WSAStartup
WSAGetLastError

 

 

Community Additions

ADD
Show:
© 2014 Microsoft