Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

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
Updated 7-Feb-13 1:00am
v3
Comments
[no name] 7-Feb-13 7:12am    
Share your code !!
Ramya singam 7-Feb-13 7:51am    
This is my code...

HttpWebRequest req = null;
HttpWebResponse res = null;
try
{
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};
xmlDoc.Load(Server.MapPath("PostData.xml"));
string sXml = xmlDoc.InnerXml;
req.ContentLength = sXml.Length;
var sw = new StreamWriter(req.GetRequestStream());
sw.Write(sXml);
sw.Close();

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();
soapResonseXmlDocument.LoadXml(streamReader.ReadToEnd());

//return only the xml representing the response details (inner request)
TextBox1.Text = soapResonseXmlDocument.InnerXml;
//Response.Write(soapResonseXMLDocument.InnerXml);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}

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

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

Debug WCF REST Service.
 
Share this answer
 
v2
Comments
Ramya singam 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();
ds.ReadXml(xmlReader);
gvView.DataSource = ds.Tables[0];
gvView.DataBind();
Ramya singam 8-Feb-13 2:39am    
Oh..I have solved myself...any way thank you
returning customlist object instead of string from my service method and read the data and bind to gridview control in application.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900