I have a discovery endpoint for my WCF service.
In my discovery client I need to search for all services of specific type. For this purpose I'm thinking to use Scope feature and WCF service metadata extension.
// Create DiscoveryClient
DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
// Find ICalculatorService endpoints
FindCriteria findCriteria = new FindCriteria(typeof(IAgent));
findCriteria.Duration = TimeSpan.FromSeconds(5);
findCriteria.Scopes.Add(new Uri("net.tcp://cybertech.com/CallTesting/AgentService/1/Cisco"));
FindResponse findResponse = discoveryClient.Find(findCriteria);
Is it possible to configure service endpoint metadata like Scope and Extensions in code. If yes, what is the API for that? I didn't found much on the internet.
I need in-code solution, because I'm hosting service in-code and i'm not using XML configuration.
Found solution to add it in code:
var address = CommonMethods.GetIpLocalAddress();
_host = new ServiceHost(typeof(AgentService), new Uri(string.Format("net.tcp://{0}/AgentService", address)));
var endpoint = _host.AddServiceEndpoint(typeof(IAgent), new NetTcpBinding(), String.Empty);
var metadataProvider = new CiscoMetaDataProvider();
var discoveryBehavior = new EndpointDiscoveryBehavior();
discoveryBehavior.Scopes.Add(new Uri("net.tcp://blablabla.com/CallTesting/AgentService/1/Cisco"));
discoveryBehavior.Extensions.Add(new XElement("phoneNumber", metadataProvider.GetPhoneNumber()));
endpoint.Behaviors.Add(discoveryBehavior);
var discoveryEndpoint = new UdpDiscoveryEndpoint();
_host.AddServiceEndpoint(discoveryEndpoint);
ServiceDiscoveryBehavior serviceDiscoveryBehavior = new ServiceDiscoveryBehavior();
serviceDiscoveryBehavior.AnnouncementEndpoints.Add(new UdpAnnouncementEndpoint());
_host.Description.Behaviors.Add(serviceDiscoveryBehavior);
_host.Open();