コード例 #1
0
ファイル: Program.cs プロジェクト: yongzhao1/dotnet-samples
        public static void Main(string[] args)
        {
            Console.WriteLine(" **** Announcement service ****");
            AnnouncementService announcementService = new AnnouncementService();

            announcementService.OnlineAnnouncementReceived  += new EventHandler <AnnouncementEventArgs>(announcementService_OnlineAnnouncementReceived);
            announcementService.OfflineAnnouncementReceived += new EventHandler <AnnouncementEventArgs>(announcementService_OfflineAnnouncementReceived);

            // Search for the signing certificate in StoreLocation.LocalMachine, StoreName.My, using FindBySubjectDistinguishedName
            // Keep the default settings for client certificates (used to validate incoming messages): StoreLocation.LocalMachine, StoreName.My
            SigningCertificateSettings signingStoreSettings = new SigningCertificateSettings("CN=DiscoverySecureServiceCertificate");

            ServiceHost host = new ServiceHost(announcementService);

            UdpAnnouncementEndpoint announcementEndpoint = new UdpSecureAnnouncementEndpoint(
                DiscoveryVersion.WSDiscovery11,
                signingStoreSettings);

            try
            {
                host.AddServiceEndpoint(announcementEndpoint);
                host.Open();

                Console.WriteLine("\nPress enter to exit ..");
                Console.ReadLine();
                host.Close();
            }
            catch (CommunicationException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (TimeoutException e)
            {
                Console.WriteLine(e.Message);
            }

            if (host.State != CommunicationState.Closed)
            {
                Console.WriteLine("Aborting the service...");
                host.Abort();
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        public static void Main(string[] args)
        {
            Console.WriteLine(" **** Announcement service ****");
            AnnouncementService announcementService = new AnnouncementService();
            announcementService.OnlineAnnouncementReceived += new EventHandler<AnnouncementEventArgs>(announcementService_OnlineAnnouncementReceived);
            announcementService.OfflineAnnouncementReceived += new EventHandler<AnnouncementEventArgs>(announcementService_OfflineAnnouncementReceived);

            // Search for the signing certificate in StoreLocation.LocalMachine, StoreName.My, using FindBySubjectDistinguishedName
            // Keep the default settings for client certificates (used to validate incoming messages): StoreLocation.LocalMachine, StoreName.My
            SigningCertificateSettings signingStoreSettings = new SigningCertificateSettings("CN=DiscoverySecureServiceCertificate");

            ServiceHost host = new ServiceHost(announcementService);

            UdpAnnouncementEndpoint announcementEndpoint = new UdpSecureAnnouncementEndpoint(
                DiscoveryVersion.WSDiscovery11,
                signingStoreSettings);

            try
            {
                host.AddServiceEndpoint(announcementEndpoint);
                host.Open();

                Console.WriteLine("\nPress enter to exit ..");
                Console.ReadLine();
                host.Close();
            }
            catch (CommunicationException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (TimeoutException e)
            {
                Console.WriteLine(e.Message);
            }

            if (host.State != CommunicationState.Closed)
            {
                Console.WriteLine("Aborting the service...");
                host.Abort();
            }
        }