1

On my console application I am making following webClient Request to upload the data.

using (var client = new WebClient())
{
    client.Headers.Clear();
    client.Headers.Add("Content-Type", "application/json; charset=utf-8");
    client.UploadStringCompleted += (data, exception) =>
    {
        if (exception.Error != null)
        {
            _log.Error("Error While Posting XYZSets data {0}", exception.Error);
        }
        client.Dispose();
    };
    var ApplicationUrl = string.Format("{0}/api/AAA/PostXYZSets", ConfigurationManager.AppSettings["ApplicationUrl"]);
    client.UploadStringAsync(new Uri(ApplicationUrl), jsonData);
}

In my MVC application at some point I am returning the IHttpActionResult by following code.

[ServiceAuthentication]
public IHttpActionResult PostXYZSets(XYZSet[] xYZSets)
{
    return BadRequest("My Custom Error message"); 
}

But when UploadStringCompleted method receives exception, I nowhere find "My Custom Error message". it says (400) Bad Request.

Tell me what's wrong am i doing. thanks in advance.

Federico Dipuma
  • 17,655
  • 4
  • 39
  • 56

1 Answers1

0

The response is in the string returned, not in the header. It's there. Just read the return string as you would read an Ok response.