1

そんなサービスを作りたいです。サービスが開始されると、p2pなど、同じマシンで実行中の他のサービスを見つけることができます。WCFのNetNamedPipeBindingを使用したい。

そして、どのように実装するのですか?

更新' 私はこれを試してみます。

サービス開始」

    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);
        }
    }

サービスを探す」

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;
        }
    }

しかし問題は、最初に開始されたサービスしか見つけられないことです。私に何ができる ?

4

1 に答える 1

0

WCF Discovery Protocolを確認してください。

于 2012-05-08T00:11:26.860 に答える