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(); }
public void CloseWindow() { if (notificationServiceClient != null) { try { if (notificationServiceClient.State != CommunicationState.Faulted) { notificationServiceClient.Unsubscribe(userId); notificationServiceClient.Close(); } } catch { notificationServiceClient.Abort(); } } }