Web Api XML response Issue getting error.

Dec 30 2016 5:10 AM
Here i have two web api project's (webapi with mvc and Web api).
Now I'm sending xml request to web api project then i got the response now I'm tying to convert taht xml response into object getting error.please can help me anyone.I have tried many way but still getting error.
 
From here I'm calling  to my web api project. im getting proper xml response but im trying to convert it into object getting error
 
namespace example.BLL
{
public class ExampleApiBLL
{
private static readonly string smapleurl= ConfigurationManager.AppSettings["smapleURL"];
public GetsampleResponse  smpleAPI(SampleDTO objInput)
{
string json = string.Empty; string jsonReturn = string.Empty;
GetsampleResponse smapleres= new GetsampleResponse ();
try
{
json = new JavaScriptSerializer().Serialize(new
{
Name = objInput.Name,
Userid = objInput.id, SecurityKey = objInput.SecurityKey,
PassWord = objInput.PassWord,
Lang = "EN"
});
var httpWebRequest = (HttpWebRequest)WebRequest.Createsmapleurl+ "api/webapicontrollername");
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = WebRequestMethods.Http.Post;
httpWebRequest.KeepAlive = true;
httpWebRequest.Headers.Add("Cache-Control", "no-cache");
httpWebRequest.Accept = "*/*";
httpWebRequest.Headers.Add("Accept-Encoding", "gzip,deflate");
httpWebRequest.Headers.Add("Accept-Language", "en-gb,en;q=0.5");
httpWebRequest.Timeout = 300000;
var requestBody = Encoding.UTF8.GetBytes(json);
httpWebRequest.ContentLength = requestBody.Length;
using (var streamWriter = httpWebRequest.GetRequestStream())
{
streamWriter.Write(requestBody, 0, requestBody.Length);
streamWriter.Flush();
streamWriter.Close();
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
string xmlString = streamReader.ReadToEnd();
smapleres= (GetsampleResponse )XMLToObject(xmlString, smapleres);
}
}
catch (Exception ex)
{
var message = ex.Message;
}
return smapleres; //return jsonReturn;
}
public Object XMLToObject(string XMLString, Object oObject)
{
XmlSerializer oXmlSerializer = new XmlSerializer(oObject.GetType());
oObject = oXmlSerializer.Deserialize(new StringReader(XMLString));
return oObject;
}
}
}

Answers (1)