1

I have an issue where a function is not being called. My guess is that it is a synchronization problem.

Here is the code:

await context.PostAsync("Foo Bar");

The function below doesn't seem to be called if I put it before or after the POST to the web server.

context.Call(new QuestionFourDialog(), this.QuestionFourResumeAfter);

Uri baseUri = new Uri("http://somedomain.com/");
UriBuilder builder = new UriBuilder($"{baseUri}/analytics/message?");

using (WebClient webclient = new WebClient())
{
    webclient.Encoding = System.Text.Encoding.UTF8;
    webclient.Headers.Add("Content-Type", "application/json");

    string postBody = $"{{\"message\": \"{this.answer}\", \"key\": \"7F02D18E-88E7-486D-B51F-550118491CB1\"}}";

    webclient.UploadString(builder.Uri, postBody);
}

Is there a way I can call the POST code asynchronous or another way to solve this issue ?

Joel Parker
  • 295
  • 1
  • 4
  • 17
  • How are you calling your function? – SLaks Sep 08 '17 at 18:24
  • The code above is encapsulated in an async function private async Task QuestionThreeResumeAfter(IDialogContext context, IAwaitable result) it is a handler in a dialog chain. It is worth noting that if I comment out the webclient stuff it works as expected. – Joel Parker Sep 08 '17 at 18:36

1 Answers1

0

I replaced this line

webclient.UploadString(builder.Uri, postBody);

with

webclient.UploadStringAsync(builder.Uri, postBody);

and now it works perfectly.

Joel Parker
  • 295
  • 1
  • 4
  • 17