예제 #1
0
 void Broadcast(FromServerToClientData data)
 {
     Context.Post(delegate
     {
         TextBox textBox = (TextBox)Page.FindName("BroadcastText");
         textBox.Text    = string.Format("Broadcast: {0} {1} {2}", data.Now, data.Integer, data.Text);
     }, null);
 }
예제 #2
0
 void OthersCallback(FromServerToClientData data)
 {
     Context.Post(delegate
     {
         TextBox textBox = (TextBox)Page.FindName("OthersCallbackText");
         textBox.Text    = string.Format("OthersCallback: {0}", data.Text);
     }, null);
 }
예제 #3
0
        public async void RunAsync()
        {
            HubConnection connection = new HubConnection("http://localhost:18628/");
            IHubProxy     proxy      = connection.CreateHubProxy("SampleHub");

            proxy.On <FromServerToClientData>("Broadcast", Broadcast);
            proxy.On <string>("BroadcastToGroup", BroadcastToGroup);
            proxy.On <FromServerToClientData>("OthersCallback", OthersCallback);
            await connection.Start();

            FromServerToClientData request = new FromServerToClientData();

            request.Text = "This is a request from a WindowsStoreApp!";

            proxy.Invoke <FromClientToServerData>("Request", request).ContinueWith(task =>
            {
                FromClientToServerData response = task.Result;
                Context.Post(delegate
                {
                    TextBox textBox = (TextBox)Page.FindName("ResponseText");
                    textBox.Text    = string.Format("Response: {0}", response.Text);
                }, null);
            });

            proxy.Invoke <FromClientToServerData>("RequestAsync", request).ContinueWith(task =>
            {
                FromClientToServerData response = task.Result;
                Context.Post(delegate
                {
                    TextBox textBox = (TextBox)Page.FindName("ResponseAsyncText");
                    textBox.Text    = string.Format("ResponseAsync: {0}", response.Text);
                }, null);
            });

            proxy.Invoke("RequestWithCallbackAsync", request);
            proxy.Invoke("JoinGroup", "WindowsStoreApp");
        }