WsAddCustomHeader function (webservices.h)

Adds the specified application-defined header to the message.


HRESULT WsAddCustomHeader(
  [in]           WS_MESSAGE                   *message,
  [in]           const WS_ELEMENT_DESCRIPTION *headerDescription,
  [in]           WS_WRITE_OPTION              writeOption,
  [in, ref]      const void                   *value,
  [in]           ULONG                        valueSize,
  [in]           ULONG                        headerAttributes,
  [in, optional] WS_ERROR                     *error


[in] message

The message to which to add the header.

The message can be in any state except WS_MESSAGE_STATE_EMPTY (see the WS_MESSAGE_STATE enumeration..

[in] headerDescription

The WS_ELEMENT_DESCRIPTION structure that describes the header.

[in] writeOption

Whether the header element is required, and how the value is allocated. For more information, see the WS_WRITE_OPTION enumeration.

[in, ref] value

The header value to serialize. For more information, see the WS_WRITE_OPTION enumeration.

[in] valueSize

The size of the value being serialized, in bytes.

[in] headerAttributes

The values of the SOAP attributes for the header.

[in, optional] error

Pointer to a WS_ERROR structure that receives additional error information if the function fails.

Return value

If the function succeeds, it returns NO_ERROR; otherwise, it returns an HRESULT error code.

Return code Description
There are multiple instances of the same type of header present in the message.
Insufficient memory to complete the operation.
One or more of the parameters are incorrect.
Other Errors
This function may return other errors not listed above.


The WsAddCustomHeader function is designed handle types of headers that are targeted at the final receiver. Headers targeted at another receiver are ignored.

If you are replacing a header, call the WsRemoveCustomHeader function to remove the existing instances of the header before calling WsAddCustomHeader.


Minimum supported client Windows 7 [desktop apps | UWP apps]
Minimum supported server Windows Server 2008 R2 [desktop apps | UWP apps]
Target Platform Windows
Header webservices.h
Library WebServices.lib
DLL WebServices.dll