i create a wcf-lib, i just want a interprocess communication. when i open a app, who is use the lib, will announce each other. i use UdpAnnouncementEndpoint, it work. but it will receive the announcement from Intranet. what can i do ?
and i create endpoint by code like this:
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;
}
and add a AnnouncementsListener in the host:
private void ActionInitAnnouncementsListener()
{
var announcementService = new AnnouncementService();
announcementService.OnlineAnnouncementReceived += OnOnlineAnnouncementReceived;
announcementService.OfflineAnnouncementReceived += OnOfflineAnnouncementReceived;
_announcementsListener = new ServiceHost(announcementService);
_announcementsListener.AddServiceEndpoint(new UdpAnnouncementEndpoint());
}
I apologize, I was looking at the wrong part of your code. You are not using the named pipes in order to make your client discoverable.
Here it is how you can get the IP address of the incoming message (I assume that based on that IP address you can deduce using some code logic if your message comes from your intranet or not).
OperationContext context = OperationContext.Current;
MessageProperties messageProperties = context.IncomingMessageProperties;
RemoteEndpointMessageProperty endpointProperty = messageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
The above code was founnd on the following link: http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/f14520be-d77d-401f-b339-9c58585857f7/
You cana also find more in depth details on http://www.danrigsby.com/blog/index.php/2008/08/20/observableservicehost-an-instancecontext-creation-aware-wcf-servicehost/.