Adjusting discovery-related information for the service's application endpoint and adjusting some of the discovery-related settings on the standard endpoint.
To enable discovery, a few changes must be made in the application configuration file for the service:
A discovery endpoint must be added to the <service> element. This is a standard UdpDiscoveryEndpoint endpoint. This is a system endpoint that the runtime associates with the discovery service. The discovery service listens for messages on this endpoint.
A <serviceDiscovery> behavior is added to the <serviceBehaviors> section. This enables the service to be discovered at run time and uses the discovery endpoint mentioned previously to listen for discovery Probe and Resolve messages. With these two additions, the service is discoverable at the discovery endpoint specified.
The following config snippet shows a service with an application endpoint and a discovery endpoint defined:
To take advantage of announcements, you will need to add an announcement endpoint. To do this, modify the configuration file as shown in the following code.
Adding an announcement endpoint to the discovery service behavior creates a default announcement client for the service. This guarantees that the service will send an online and offline announcement when the service is opened and closed respectively.
This configuration file goes beyond just those simple steps by modifying additional behaviors. It is possible to control discovery-related information by using specific endpoints. That is, a user can control whether an endpoint can be discovered and the user can also mark that endpoint with Scopes and custom XML metadata. To do this, the user must add a behaviorConfiguration property to the application endpoint. In this case, the following property is added to the application endpoint.
Now, through the behavior configuration element, you can control discovery-related attributes. In this case, two scopes are added to the application endpoint.
You can also control specific details of the discovery endpoint. This is done through the StandardEndpointsSection. In this sample, the version of the protocol used is modified as well as adding a maxResponseDelay attribute as shown in the following code example.
In the application configuration file for the client, a standardEndpoint of type dynamicEndpoint is used to utilize discovery as shown in the following config snippet.
<client>
<!-- Create an endpoint, make kind="dynamicEndpoint" and use the endpointConfiguration to change settings of DynamicEndpoint -->
<endpoint name="calculatorEndpoint"
binding="wsHttpBinding"
contract="ICalculatorService"
kind ="dynamicEndpoint"
endpointConfiguration="dynamicEndpointConfiguration">
</endpoint>
</client>
When a client is using a dynamicEndpoint, the runtime performs discovery automatically. Various settings are used during discovery, such as those defined in the discoveryClientSettings section, which specifies the type of discovery endpoint to use:
<!-- Add Scopes, ScopeMatchBy, Extensions and termination criteria in FindCriteria -->
<findCriteria scopeMatchBy="http://schemas.microsoft.com/ws/2008/06/discovery/rfc" duration="00:00:10" maxResults="1">
<scopes>
<add scope="http://www.microsoft.com/building42/floor1"/>
</scopes>
<!-- These extensions are sent from the client to the service as part of the probe message -->
<extensions>
<CustomMetadata>This is custom metadata that is sent to the service along with the client's find request.</CustomMetadata>
</extensions>
</findCriteria>
This sample extends this feature and modifies the FindCriteria used by the client, as well as some properties of the standard updDiscoveryEndpoint used for discovery. The FindCriteria are modified to use a scope and a specific scopeMatchBy algorithm, as well as custom termination criteria. Furthermore, the sample also shows how a client can send XML elements using Probe messages. Lastly, some changes are made to the UdpDiscoveryEndpoint, such as the version of the protocol used and UDP-specific settings as shown in the following configuration file.
<udpDiscoveryEndpoint>
<!-- Specify the discovery protocol version and UDP transport settings. -->
<standardEndpoint name="adhocDiscoveryEndpointConfiguration" discoveryVersion="WSDiscovery11">
<transportSettings duplicateMessageHistoryLength="2048"
maxPendingMessageCount="5"
maxReceivedMessageSize="8192"
maxBufferPoolSize="262144"/>
</standardEndpoint>
</udpDiscoveryEndpoint>
The following is the complete client configuration used in the sample.
<configuration>
<system.serviceModel>
<client>
<!-- Create an endpoint, make kind="dynamicEndpoint" and use the endpointConfiguration to change settings of DynamicEndpoint -->
<endpoint name="calculatorEndpoint"
binding="wsHttpBinding"
contract="ICalculatorService"
kind ="dynamicEndpoint"
endpointConfiguration="dynamicEndpointConfiguration">
</endpoint>
</client>
<standardEndpoints>
<dynamicEndpoint>
<standardEndpoint name="dynamicEndpointConfiguration">
<discoveryClientSettings>
<!-- Controls where the discovery happens. In this case, Probe message is sent over UdpDiscoveryEndpoint. -->
<endpoint kind="udpDiscoveryEndpoint" endpointConfiguration="adhocDiscoveryEndpointConfiguration" />
<!-- Add Scopes, ScopeMatchBy, Extensions and termination criteria in FindCriteria -->
<findCriteria scopeMatchBy="http://schemas.microsoft.com/ws/2008/06/discovery/rfc" duration="00:00:10" maxResults="1">
<scopes>
<add scope="http://www.microsoft.com/building42/floor1"/>
</scopes>
<!-- These extensions are sent from the client to the service as part of the probe message -->
<extensions>
<CustomMetadata>This is custom metadata that is sent to the service along with the client's find request.</CustomMetadata>
</extensions>
</findCriteria>
</discoveryClientSettings>
</standardEndpoint>
</dynamicEndpoint>
<udpDiscoveryEndpoint>
<!-- Specify the discovery protocol version and UDP transport settings. -->
<standardEndpoint name="adhocDiscoveryEndpointConfiguration" discoveryVersion="WSDiscovery11">
<transportSettings duplicateMessageHistoryLength="2048"
maxPendingMessageCount="5"
maxReceivedMessageSize="8192"
maxBufferPoolSize="262144"/>
</standardEndpoint>
</udpDiscoveryEndpoint>
</standardEndpoints>
</system.serviceModel>
</configuration>
To use this sample
This sample uses HTTP endpoints and to run this sample, proper URL ACLs must be added. For more information, see Configuring HTTP and HTTPS. Executing the following command at an elevated privilege should add the appropriate ACLs. You may want to substitute your Domain and Username for the following arguments if the command does not work as is. netsh http add urlacl url=http://+:8000/ user=%DOMAIN%\%UserName%
Build the solution.
Run the service executable from the build directory.
Run the client executable. Note that the client is able to locate the service.
This module examines how clients connect to Microsoft 365. It also provides instruction on how to configure name resolution and Outlook clients, and how to troubleshoot client connectivity.