I have created a basic WCF REST web service in C#, and I need it to accept a content type of "application/xml" in an HTTP POST. The code I have will only work if the content type of the POST is "application/x-www-form-urlencode", and when I try to make the POST data content type of "application/xml", I get a 400 error message.
The WCF web service is using a behaviorConfiguration of "RestBehavior" and a binding of "webHttpBinding".
The client code that is composing and sending the post is like the following:
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(GetURL());
request.Method = "POST";
request.ContentLength = byteArray.Length;
request.ContentType = "application/xml";
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
Stream data = response.GetResponseStream();
response.Close();
When I change the content type to "application/x-www-form-urlencoded" it works, but this client code here gets a 400 error from the web service. I need this to work with content type of "application/xml". Thanks.