Home | Documentation |
The WS-Discovery plugin
updated Thu Mar 21 2024 by Robert van Engelen
|
The material in this section relates to the WS-Discovery specification.
To use the wsdd library:
The material in this document pertains to the WS-Discovery protocol and model and assumes that the reader is familiar with the WS-Discovery protocol, its terms and definitions, and the WS-Discovery model. This document describes the WS-Discovery interface to invoke and handle WS-Discovery events, while the higher-level logic remains application-specific. Especially the mode of operation, ad-hoc or managed with a Discovery Proxy, depends on the application deployment and WS-Discovery support requirements.
The following assumptions are made. A Client (C) is an endpoint that searches for Target Service(s). A Target Service (TS) is a service endpoint that makes itself available for discovery. A Discovery Proxy (DP) is an endpoint that facilitates discovery of Target Services by Clients. The interfaces defined in the wsdd library can be used to implement Client, Target Service, and Discovery Proxy operations.
WS-Discovery ad-hoc and managed modes are supported by the wsdd library. In an ad-hoc mode discovery messages are sent multicast and response messages are sent unicast. In a managed mode discovery messages are sent unicast to a Discovery Proxy.
SOAP_XML_TREE
flag or compile the source code with WITH_NOIDREF
.The following event handlers MUST be defined by the user to handle inbound WS-Discovery messages. The event handlers receive notifications (Hello, Bye, ProbeMatches, and ResolveMatches) or receive requests to provide data (Probe and Resolve).
The event handlers to define are:
See the documentation provided with each of these functions in wsddapi.h.
Inbound WS-Discovery multicast messages are handled via a listener on a port. The user-defined event handlers are invoked when WS-Discovery messages arrive on the port.
The soap_wsdd_listen
function listens on the current port opened with soap_bind
for WS-Discovery messages for a brief time period as specified by a timeout value in seconds (negative for micro seconds). The function allows for periodically polling the port as shown:
WS-Discovery messages are relayed to the event handlers. The soap->user pointer can be used to point to a state object that is updated by the event handlers as per desired behavior at the Client side, the Target Service, or the Discovery Proxy implementation.
A Client may invoke the following WS-Discovery operations:
soap_wsdd_Probe
soap_wsdd_Resolve
A Target Service may invoke the following WS-Discovery operations:
soap_wsdd_Hello
soap_wsdd_Bye
soap_wsdd_ProbeMatches
(e.g. via soap_wsdd_listen
)soap_wsdd_ResolveMatches
(e.g. via soap_wsdd_listen
)A Discovery Proxy can perform all operations listed above, and should use "wsdd:DiscoveryProxy" as the Type with the Hello, Bye, and ProbeMatches.
To send a Hello message to join a network:
Note that Types
above is a string with namespace-qualified names (QNames). These should be qualified as in "namespace":name or you can use a namespace prefix that is part of your namespace table (in the .nsmap). So you can use "wsdd:DiscoveryPRoxy" as a QName in Types because wsdd is a namespace prefix with a defined binding in the namespace table.
For UDP multicast, use
and optionally set the interface and TTL settings:
Please refer to the socket options for IPPROTO_IP
IP_MULTICAST_IF
to specify the default interface for multicast datagrams to be sent from. Otherwise, the default interface set by the system administrator will be used (if any).
Please refer to the socket options for IPPROTO_IP
IP_MULTICAST_TTL
to limit the lifetime of the packet. Multicast datagrams are sent with a default value of 1, to prevent them to be forwarded beyond the local network. This parameter can be set between 1 to 255.
To send a Bye message to leave a network:
To send a Probe message (see WS-Discovery 1.1 Section 1.7) and then listen to ProbeMatches:
The id
above is the WS-Addressing message ID that will be included in the ProbeMatches RelatesTo WS-Addressing header. As an example, my_state
is set to this id
so that when the wsdd_event_ProbeMatches
event handler is invoked it can find the id
in the current state that is pointed to by serv->user
(soap->user
in the handler).
To send a Resolve message and then listen to ResolveMatches:
Again, the id
and my_state
are used to associate the asynchronously received ResolveMatches response that is handled by the wsdd_event_ResolveMatches for the original request.
In managed mode with unicast messages (request-response messages), the soap_wsdd_Probe
and soap_wsdd_Resolve
are sufficient to invoke without setting up a listener. The event handlers are invoked when the unicast response message arrives.
In managed mode, the ProbeMatches and ResolveMatches are automatically sent via soap_wsdd_listen
and the event wsdd_event_Probe
and wsdd_event_Resolve
handlers. These event handlers should set the matches to be returned.
In ad-hoc mode, ProbeMatches or ResolveMatches responses are NOT sent automatically. In ad-hoc mode the responses can be returned by adding code to the event handler or from anywhere in the main program, for example after soap_wsdd_listen. When responses are to be returned from the event handler or from the main program, you should invoke soap_wsdd_ProbeMatches and soap_wsdd_ResolveMatches to explicitly send unicast messages with the match(es) back to the clients. The WS-Addressing ReplyTo address can be used as the return address (when not anonymous), or by using the peer's host information that is accessible in the soap->peer and soap->peerlen members. For example:
The soap_wsdd_ProbeMatches function takes an array of wsdd__ProbeMatchesType matches to transmit. This array is created by calling functions soap_wsdd_init_ProbeMatches and then soap_wsdd_add_ProbeMatch multiple times. Each call adds an element to the matches:
After calling soap_wsdd_add_ProbeMatch it is possible to add additional WS-Addressing header values to this matches array element. For example the WS-Addressing reference parameters channel instance:
See also the Data binding documentation on allocating and initializing C/C++ data in managed memory, managed by the soap
context.
The WSDD plugin is developed to support C and C++. To support C++ server objects generated with soapcpp2 option -j
(or -i
), run soapcpp2 again:
soapcpp2 -a -j -Iimport import/wsdd.h
You should define in your C++ code the following wrappers (use this
instead of this->soap
below with soapcpp2 option -i
):
Note that soapcpp2 option -a
may be needed to enable automatic service dispatching of WS-Addressing services based on the SOAP Action value instead of the SOAP/XML request operation.
Another approach to generate the WSDD service operations is to run soapcpp2 separately on wsdd.h (or wsdd5.h or wsdd10.h for WS-Discovery 1.0) by:
soapcpp2 -a -L -pwsdd -Iimport import/wsdd.h
Now with this approach you must chain the service operations at the server side as follows:
where the service
object is an instance of the application services generated by soapcpp2 -j
.
Then compile the generated wsddClient.cpp file with the macro -DSOAP_H_FILE=wsddH.h
to specify that wsddH.h
should be used instead of `soapH.h.
To combine WS-Security with WS-Discovery, please see the next section.
You must generate client-side operations that the WSDD library expects to be linked with, by executing:
soapcpp2 -a -L -pwsdd -Iimport import/wsdd.h
Then compile the generated wsddClient.cpp file with the macro -DSOAP_H_FILE=wsddH.h
to specify that wsddH.h
should be used instead of `soapH.h.
If WS-Security is used with WS-Discovery, then create a file imports.h
with the following two lines:
Then execute:
soapcpp2 -a -L -pwsdd -Iimport imports.h
This generates wsddC.cpp and wsddClient.cpp, which should be compiled together with plugin/wsddapi.c, plugin/wsseapi.c, plugin/mecevp.c, and plugin/smdevp.c. All files should be compiled with -DSOAP_H_FILE=wsddH.h
, i.e. macro SOAP_H_FILE
set to wsddH.h
. WS-Security requires OpenSSL and linkage with libssl and libcrypto.
For server-side projects, also compile and link the generated wsddServer.cpp code. You will also need to implement the WS-Discovery Event Handlers.
Because WS-Addressing may relay faults to a FaultTo service, when implementing a service you will also have to define a SOAP Fault service operation to accept and handle these:
When implementing a WS-Discovery client and/or server without any other XML Web services, the above suffices to generate the required code.