“(500) Internal Server Error” when POSTing JSON

Just spent probably 2 hours on trying to figure this out.. Super-simple POST to a rest api, along those lines:

 
public static string SendToWebService(string url, CommunicationMessageBase message)
        {
            if (string.IsNullOrEmpty(url))
                throw new ArgumentException("Empty url");
            if (message == null)
                throw new ArgumentException("Message is null.");
 
            using (WebClient client = new WebClient())
            {
                client.Headers.Add("Content-Type", "application/json");
                return client.UploadString(url, "POST", message.ToJSON());
            }
        }

This is a correct code, which was failing, returning server 500 error. Basically, I was passing an object of a class, inhrerited from CommunicationMessageBase.. And I forgot to define parameterless constructor on the child class! D-uh!

Leave a Reply

Your email address will not be published. Required fields are marked *