Click here to Skip to main content
13,054,615 members (66,945 online)
Rate this:
Please Sign up or sign in to vote.
See more:

i created wcf REST ApI service and hosed in IIS 7.5.but when i accessing service through web application i got message like
"The remote server returned an error: (415) Cannot process the message because the content type 'application/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'.. "

For fixing this issue i changed the content type to "application/soap+xml; charset=utf-8". this issue is fixed but i got another issue like

"The remote server returned an error: (400) Bad Request"

Please Help me.

Thank you in Advance.
Posted 7-Feb-13 0:38am
Updated 7-Feb-13 1:00am
Krunal Rohit 7-Feb-13 7:12am
Share your code !!
Ramya naidu 7-Feb-13 7:51am
This is my code...

HttpWebRequest req = null;
HttpWebResponse res = null;
const string url = "http://localhost:4567/PersonServiceImpl.svc/auth";
req = (HttpWebRequest) WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "application/xml; charset=utf-8";
req.Timeout = 30000;
req.Headers.Add("SOAPAction", url);

var xmlDoc = new XmlDocument {XmlResolver = null};
string sXml = xmlDoc.InnerXml;
req.ContentLength = sXml.Length;
var sw = new StreamWriter(req.GetRequestStream());

res = (HttpWebResponse) req.GetResponse(); //I got Error here
Stream responseStream = res.GetResponseStream();
var streamReader = new StreamReader(responseStream);

//Read the response into an xml document
var soapResonseXmlDocument = new XmlDocument();

//return only the xml representing the response details (inner request)
TextBox1.Text = soapResonseXmlDocument.InnerXml;
catch (Exception ex)
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Use Content Type text/xml as below.
req.ContentType = "text/xml";

You may also refer my Tip/Trick on the topic "Debug WCF REST Service".

Debug WCF REST Service.
Ramya naidu 8-Feb-13 1:59am
i have fixed the above issue by retuning string xml from service.but i have another problem while converting xmlstring into dataset, the dataset retuns null..

i don't know why it is retuning null.please help me

i am sharing my service method code and consuming code...

DataSet dsBuildSQL = new DataSet();
StringBuilder sbSQL;
StringWriter swSQL;
string XMLformat;

sbSQL = new StringBuilder();
swSQL = new StringWriter(sbSQL);
dsBuildSQL.Merge(DTtemp, true, MissingSchemaAction.AddWithKey);
dsBuildSQL.Tables[0].TableName = "Table";
foreach (DataColumn col in dsBuildSQL.Tables[0].Columns)
col.ColumnMapping = MappingType.Attribute;
dsBuildSQL.WriteXml(swSQL, XmlWriteMode.IgnoreSchema);
XMLformat = sbSQL.ToString();
return XMLformat;

//.Net application code

StringReader xmlReader = new StringReader(soapResonseXmlDocument.InnerXml);
DataSet ds = new DataSet();
gvView.DataSource = ds.Tables[0];
Ramya naidu 8-Feb-13 2:39am
Oh..I have solved myself...any way thank you
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

returning customlist object instead of string from my service method and read the data and bind to gridview control in application.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 8 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100