1
このようなサービスを作成したいと考えています。 サービスが開始されると、p2pのように、同じマシン上で実行中の他のサービスを見つけることができます。 WCFのNetNamedPipeBindingを使いたいです。wcfサービスで他の実行中のサービスを検出する方法
と実装方法
更新 ' 私はこれを試します。
開始サービス '
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;
}
}
が、問題はそれだけで最初に始めたサービスを見つけることができる、です。 私は何ができますか?
はい、ありがとうございます。私はそれを知っています。しかし、私はudpを使いたくありません。言い換えれば、私はそれを使う方法を理解していませんでした。私はいくつかの重要なヒントを得ることができることを願っています。 – GeminiYellow
これをチェックアウトする '[リンク](http://stackoverflow.com/questions/7068743/is-it-possible-to-use-wcf-discovery-to-expose-a-wcf-endpoint-that-is-using -named) – GeminiYellow
なぜUDPを使いたくないのですか?正当な理由があるかもしれませんが、あなたのモチベーションを知らないと、それは車輪を再発明するようですね? –