none
AnnouncementService with scope RRS feed

  • Question

  • Hi,

    I successfully implemented the listener service on client side using the AnnouncementService. However, it also fires an event when a host is getting online with the wrong contract and scope.

    How can I setup the AnnouncementService such that only hosts with a certain contract and scope will fire the 'hello' and 'bye' events?

    (comparable with the FindCriteria setup)

    Thanks!

    Martin


    • Edited by Martin2003 Tuesday, October 29, 2013 1:34 PM
    Tuesday, October 29, 2013 1:34 PM

All replies

  • Hi,

    I have test the following in my computer, hope it can help you to get start:

    IService1.cs:

    namespace WcfService3
     {
        [ServiceContract]
         public interface IService1
        {
             [OperationContract]
             string Hello(string m);
             [OperationContract]
             string Bye(string n);
         }
     } 

    Service1.svc.cs:

    namespace WcfService3
     {
        public class Service1 : IService1
         {
    
            public string Hello(string m)
             {
                 return ml;
             }
    
            public string Bye(string n)
             {
                 return nl;
             }
         }
     }          

    The Complete Code of Web.Config looks like this:

    <system.serviceModel>
         <behaviors>
           <serviceBehaviors>
             <behavior name="Behavior1">
              <serviceDiscovery>
                 <announcementEndpoints>
                   <endpoint kind="udpAnnouncementEndpoint"></endpoint>
                </announcementEndpoints>
               </serviceDiscovery>
               <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment  -->
               <serviceMetadata httpGetEnabled="true"/>
              <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
               <serviceDebug  includeExceptionDetailInFaults="false"/>
            </behavior>
           </serviceBehaviors>
         </behaviors>
         <serviceHostingEnvironment  multipleSiteBindingsEnabled="true" />
        <services>
           <service name="WcfService3.Service1" behaviorConfiguration="Behavior1">
            <endpoint address="/Simple" binding="basicHttpBinding" contract="WcfService3.IService1"></endpoint>
            <endpoint  kind="udpDiscoveryEndpoint"></endpoint>
            <host>
               <baseAddresses>
                 <add baseAddress="http://localhost:3423/Service1.svc"/>
              </baseAddresses>
             </host>
           </service>
         </services>
    
      </system.serviceModel>

    Program.cs:

    namespace ConsoleApplication1
     {
         class Program
        {
             static void Main(string[] args)
             {
                 // Create an AnnouncementService instance
                AnnouncementService announcementService = new AnnouncementService();
                // Subscribe the announcement events
                announcementService.OnlineAnnouncementReceived += OnOnlineEvent;
                 announcementService.OfflineAnnouncementReceived += OnOfflineEvent;
    
                // Create ServiceHost for the AnnouncementService
                using (ServiceHost announcementServiceHost = new ServiceHost(announcementService))
                 {
                     // Listen for the announcements sent over UDP multicast
                    announcementServiceHost.AddServiceEndpoint(new UdpAnnouncementEndpoint());
                     announcementServiceHost.Open();
                     Service1Client obj = new Service1Client();
    
                     Console.WriteLine("The Online is " + obj.Hello("Vijay prativadi"));
                     Console.WriteLine("The Offline is " + obj.Bye("Vijay prativadi"));
    
                     Console.WriteLine("Press <ENTER> to terminate.");
    
                     Console.ReadLine();
                     announcementServiceHost.Close();
    
                }
    
            }
             static void OnOnlineEvent(object sender, AnnouncementEventArgs e)
             {
    
                 Console.WriteLine("Received an online announcement from {0}",
             e.EndpointDiscoveryMetadata.Address);
                 Console.WriteLine("Received an online announcement from {0}", e.EndpointDiscoveryMetadata.ContractTypeNames.ToString());
                 Console.WriteLine("Received an online announcement from {0}", e.EndpointDiscoveryMetadata.ListenUris.ToString());
                 Console.WriteLine("Received an online announcement from {0}", e.EndpointDiscoveryMetadata.Version);
    
            }
    
            static void OnOfflineEvent(object sender, AnnouncementEventArgs e)
             {
                 Console.WriteLine("Received an offline announcement from {0}",
             e.EndpointDiscoveryMetadata.Address);
                 Console.WriteLine("Received an offline announcement from {0}",
             e.EndpointDiscoveryMetadata.ContractTypeNames.ToString());
                 Console.WriteLine("Received an offline announcement from {0}", e.EndpointDiscoveryMetadata.ListenUris.ToString());
                 Console.WriteLine("Received an offline announcement from {0}", e.EndpointDiscoveryMetadata.Version);
    
            }
         }
     }


    For more information, please try to refer to:
    #Announcement in WCF:
    http://www.freddes.se/2010/05/16/announcement-and-discovery-in-wcf-4/ .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, October 30, 2013 6:17 AM
    Moderator
  • Hello Amy,

    Thanks for your reply. Forgive me when I am wrong but your example does give a standard implementation for the announcement service, which already runs on my system. This does not solve the problem that the "OnOnlineEvent" is also called when a server goes online with the wrong contract and scope.

    I worked around it to check the EndpointDiscoveryMetadata in the "OnOnlineEvent" callback function for contract and scope. But the event is already raised then.

    Kind regards,

    Martin

    Monday, November 4, 2013 1:06 PM