我创建了一个 wcf-lib,我只想要一个进程间通信。当我打开一个使用lib的应用程序时,会互相宣布。我使用 UdpAnnouncementEndpoint,它可以工作。但它会收到来自 Intranet 的通知。我能做些什么 ?
我通过这样的代码创建端点:
private void ActionInitClientService()
{
// Create ClientSelt ServiceHost
_clientServiceHost = new ServiceHost(_clientInstance);
_clientServiceHost.AddServiceEndpoint((typeof (IClientService)), new NetNamedPipeBinding(), Info.Address);
// Make the client discoverable via Udp
// and Broadcast itself to Online announcement
_clientServiceHost.AddServiceEndpoint(new UdpDiscoveryEndpoint());
var discoveryBehavior = new ServiceDiscoveryBehavior();
discoveryBehavior.AnnouncementEndpoints.Add(new UdpAnnouncementEndpoint());
_clientServiceHost.Description.Behaviors.Add(discoveryBehavior);
_clientServiceHost.Opened += OnOpenedClientServiceHost;
_clientServiceHost.Closed += OnClosedClientServiceHost;
}
并在主机中添加一个 AnnouncementsListener:
private void ActionInitAnnouncementsListener()
{
var announcementService = new AnnouncementService();
announcementService.OnlineAnnouncementReceived += OnOnlineAnnouncementReceived;
announcementService.OfflineAnnouncementReceived += OnOfflineAnnouncementReceived;
_announcementsListener = new ServiceHost(announcementService);
_announcementsListener.AddServiceEndpoint(new UdpAnnouncementEndpoint());
}