The new version of Windows Communication Foundation comes with a new feature to perform discovery of your services. Discovery comes in two flavours: Ad-Hoc and managed. There exists a sample in the WF-WCF samples collection which is also explained on MSDN but it configures everyting programmatically in the code. In this post a brief description is given on how to configure a client that uses managed discovery.
Client endpoints are registered in the client element of the system.serviceModel section in the config file. This is also true for a client that uses managed discovery. Below is an example of such a configuration.
1: <client>2: <endpoint binding="wsHttpBinding" contract="IService" name="service"3: kind="dynamicEndpoint"4: endpointConfiguration="discoveryDynamicEndpointConfiguration" />5: </client>
The important differences with the ‘regular’ endpoint configurations are:
- No address is specified. If you add an address (even an empty one) you get the following error: The address “<some address even empty one>” is invalid. The address while using Discovery client channel should be “http://schemas.microsoft.com/discovery/dynamic”. The only valid address that you can use (as the message states) is: http://schemas.microsoft.com/discovery/dynamic. Since this is not necessary you can just omit it.
- A kind is specified. The kind should be dynamicEndpoint to specify that you want discovery on this endpoint. Be aware that this is case sensitive! If you mistype something (for example use a capital D) WCF will throw an error at you saying: Configuration endpoint extension ‘standardEndpoints/DynamicEndpoint’ could not be found. Verify that this endpoint extension is properly registered in system.serviceModel/extensions/endpointExtensions and that it is spelled correctly.
The endpoint also contains an endpoint configuration which is added to the standard endpoints (also in the system.serviceModel section) in the config file:
1: <standardEndpoints>2: <dynamicEndpoint>3: <standardEndpoint name="discoveryDynamicEndpointConfiguration">4: <discoveryClientSettings>5: <endpoint address="net.tcp://localhost:8001/Probe"6: binding="netTcpBinding" name="discoveryEndpoint"7: kind="discoveryEndpoint"8: endpointConfiguration="managedDiscoveryEndpoint" />9: </discoveryClientSettings>10: </standardEndpoint>11: </dynamicEndpoint>12: <discoveryEndpoint>13: <!-- Specify the version of WS-Discovery to use and that we are using14: managed discovery. -->15: <standardEndpoint name="managedDiscoveryEndpoint"16: discoveryVersion="WSDiscovery11"17: discoveryMode="Managed" />18: </discoveryEndpoint>19: </standardEndpoints>20:
The most important piece here is the address of the discovery client endpoint at line 5. This is the address where the DiscoveryProxy you created is hosted. This endpoint also contains a kind field (again case sensitive!) saying that this is a discovery endpoint (ie the endpoint that uses the discovery contract to communicate with the discovery proxy). At line 8 an endpoint configuration for this endpoint is defined which points to the configuration at lines 15-18.