Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
 
"I get a 400 error message" - that's your client error. Enable tracing to see why the service throws the 400. –  CodeCaster Jul 16 '13 at 14:01
 
If your xml is not in the format WCF expects it to be then you will be presented with this message. –  No One Jul 16 '13 at 14:05
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.