private async Task WriteResponseAsync(string RequestMsg, string ResponseMsg, bool urlFound, byte[] bodyArray, IOutputStream os)
{
try //The appService will die after a day or so. Let 's try catch it seperatly so the server will still return
{
var updateMessage = new ValueSet();
updateMessage.Add("Request", RequestMsg);
updateMessage.Add("Response", ResponseMsg);
var responseStatus = await appServiceConnection.SendMessageAsync(updateMessage);
}
catch (Exception) { }
try
{
MemoryStream bodyStream = new MemoryStream(bodyArray);
using (Stream response = os.AsStreamForWrite())
{
string header = GetHeader(urlFound, bodyStream.Length.ToString());
byte[] headerArray = Encoding.UTF8.GetBytes(header);
await response.WriteAsync(headerArray, 0, headerArray.Length);
if (urlFound)
await bodyStream.CopyToAsync(response);
await response.FlushAsync();
}
}
catch (Exception) { }
}