示例#1
0
文件: Program.cs 项目: mkhiami/Idemia
        static void Main(string[] args)
        {
            Console.WriteLine("Hi from Suscriber Console!");
            InstanceContext site = new InstanceContext(null, new Program());

            NotificationServiceClient client = new NotificationServiceClient(site);

            //create a unique callback address so multiple clients can run on one machine
            WSDualHttpBinding binding = (WSDualHttpBinding)client.Endpoint.Binding;
            string            clientcallbackaddress = binding.ClientBaseAddress.AbsoluteUri;

            clientcallbackaddress    += Guid.NewGuid().ToString();
            binding.ClientBaseAddress = new Uri(clientcallbackaddress);

            //Subscribe.
            Console.WriteLine("Subscribing");
            client.Subscribe();

            Console.WriteLine();
            Console.WriteLine("Press ENTER to unsubscribe and shut down client");
            Console.ReadLine();

            Console.WriteLine("Unsubscribing");
            client.Unsubscribe();

            //Closing the client gracefully closes the connection and cleans up resources
            client.Close();
        }
示例#2
0
 public void CloseWindow()
 {
     if (notificationServiceClient != null)
     {
         try
         {
             if (notificationServiceClient.State != CommunicationState.Faulted)
             {
                 notificationServiceClient.Unsubscribe(userId);
                 notificationServiceClient.Close();
             }
         }
         catch
         {
             notificationServiceClient.Abort();
         }
     }
 }