Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            MessageC m = new MessageC()
            {
                IdS = u1.Id, IdR = u2.Id, MessageS = textBox1.Text
            };

            sendMessage(m);
            textBox1.Text = "";
        }
Пример #2
0
        private bool sendMessage(MessageC m)
        {
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri("http://localhost:50086/");

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            HttpResponseMessage response = client.PostAsJsonAsync("api/sendMessage", m).Result;

            if (response.IsSuccessStatusCode)
            {
                return(true);
            }

            return(false);
        }
Пример #3
0
        private IEnumerable <MessageC> getMessages(MessageC m)
        {
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri("http://localhost:50086/");

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            HttpResponseMessage response = client.PostAsJsonAsync("api/getMessages", m).Result;

            if (response.IsSuccessStatusCode)
            {
                var messages = response.Content.ReadAsAsync <IEnumerable <MessageC> >().Result;
                return(messages);
            }

            return(null);
        }