1

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 ?

GeminiYellow
  • 1,016
  • 2
  • 12
  • 34

1 Answers1

0

Check out the WCF Discovery Protocol.

Peter K.
  • 8,028
  • 4
  • 48
  • 73
  • yes,thanks for you help, i know it.but i dont want to use udp. Or other words, I didn't understand how to use it. I hope I can get some key points hints. – GeminiYellow May 08 '12 at 00:31
  • 1
    Check out this' [link](http://stackoverflow.com/questions/7068743/is-it-possible-to-use-wcf-discovery-to-expose-a-wcf-endpoint-that-is-using-named) – GeminiYellow May 08 '12 at 09:52
  • Why don't you want to use UDP? There might be valid reasons, but without knowing your motivation it seems like re-inventing the wheel? – Peter K. May 08 '12 at 13:26
  • oh,yes.i just want to know how it work. ok, for example, the udpdiscovery's default timeout is 20s. and,i change it to 0.5s. how could i know if all the client are got in the same pc. and how could i check the service is running? – GeminiYellow May 08 '12 at 23:56