I want to create such a service. When a service start ,it can find other running service in the same machine,like p2p. i want to use WCF's NetNamedPipeBinding.
and, how to implement?
Update' I try this.
start service'
private void ActionInitService()
{
try
{
_host = new ServiceHost(this, new Uri(ADDRESS_PIPE_BASE));
var binding = new NetNamedPipeBinding();
_host.AddServiceEndpoint((typeof (IClientService)), binding, Address.ToString());
// ** DISCOVERY ** //
_host.Description.Behaviors.Add(new ServiceDiscoveryBehavior());
_host.AddServiceEndpoint(new DiscoveryEndpoint(binding, new EndpointAddress(ADDRESS_PIPE_BASE)));
}
catch (Exception ex)
{
Debug.WriteLine("exp: " + ex);
}
}
find service'
public ObservableCollection<string> FindRunningClient()
{
var endpoints = new ObservableCollection<string>();
try
{
var binding = new NetNamedPipeBinding();
var address = new EndpointAddress(ADDRESS_PIPE_BASE);
var discoveryClient = new DiscoveryClient(new DiscoveryEndpoint(binding, address));
FindResponse rk2Clients = discoveryClient.Find(new FindCriteria(typeof(IClientService)));
discoveryClient.Close();
if (rk2Clients.Endpoints.Count != 0)
{
foreach (EndpointDiscoveryMetadata endpoint in rk2Clients.Endpoints)
{
endpoints.Add(endpoint.Address.ToString());
}
}
return endpoints;
}
catch (Exception e)
{
return endpoints;
}
}
but the problem is, it can only find the first started service. what can i do ?