Beispiel #1
0
        private void OpenServices()
        {
            // Create a singleton instance for the host
            ChatService chatService = new ChatService(this);
            chatServiceHost = new ServiceHost(chatService, this.localAddress);

            // Create a discovery behavior
            EndpointDiscoveryBehavior endpointDiscoveryBehavior = new EndpointDiscoveryBehavior();

            // Add an extension element with the username
            endpointDiscoveryBehavior.Extensions.Add(
                new XElement(
                    "root",
                    new XElement("Name", this.userName)));

            // Find the endpoint
            ServiceEndpoint simpleEndpoint =
                this.chatServiceHost.Description.Endpoints.Find(typeof(ISimpleChatService));

            // Add our behavior to the endpoint before opening it
            simpleEndpoint.Behaviors.Add(endpointDiscoveryBehavior);

            ShowStatus("Opening chat service...");
            chatServiceHost.BeginOpen(
                (result) =>
                {
                    chatServiceHost.EndOpen(result);
                    ShowStatus("Chat service ready");
                },
                null);
            OpenAnnouncementService();
        }