Beispiel #1
0
        public async Task <string> PerformSignificantWork(string message)
        {
            //i a real world we would stream this to avoid memory pressure
            SomeUnitOfWork work = new SomeUnitOfWork {
                ImportantMessage = message
            };
            var messagePayload = JsonConvert.SerializeObject(work);

            using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(messagePayload)))
            {
                using (HttpClient client = new HttpClient(_Handler, false))
                {
                    var request = new HttpRequestMessage
                    {
                        RequestUri = new Uri(string.Format("https://{0}/{1}/test/DoSignificantWork", _RelayNamespace, _ConnectionName)),
                        Method     = HttpMethod.Post,
                        Content    = new StreamContent(stream),
                    };
                    request.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
                    request.Headers.Add("ServiceBusAuthorization", await GetTokenAsync());
                    var response = await client.SendAsync(request);

                    response.EnsureSuccessStatusCode();

                    //again we would stream this to the object in real world
                    var content = await response.Content.ReadAsStringAsync();

                    return((JsonConvert.DeserializeObject <SomeUnitOfWorkResponse>(content)).Response);
                }
            }
        }
Beispiel #2
0
 public IActionResult DoSignificantWork([FromBody] SomeUnitOfWork body)
 {
     return(Ok(new SomeUnitOfWorkResponse {
         Response = $"Hello {body.ImportantMessage}"
     }));
 }