Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: IIS .NET4 IIS7.5
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 7-Feb-13 1:38am
Edited 7-Feb-13 2:00am
v3
Comments
Krunal Rohit at 7-Feb-13 7:12am
   
Share your code !!
Ramya naidu at 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);
}
Rate this: bad
good
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.
  Permalink  
v2
Comments
Ramya naidu at 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 naidu at 8-Feb-13 2:39am
   
Oh..I have solved myself...any way thank you
Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,917


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 8 Feb 2013
Copyright © CodeProject, 1999-2014
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