Following function will expect a generic List and serialize into xml and make an http post request and after receiving response it will again deserialize xml into generic list:-
public customer CreateOrder(customer objCustomerRequest)
{
customer objCustomer = new customer();
if (objCustomerRequest == null)
{
throw new ArgumentNullException("composite");
}
else
{
List<customer> customerList = new List<customer>();
XmlSerializer xmlSerializer = new XmlSerializer(objCustomer.GetType());
StringWriter textWriter = new StringWriter();
xmlSerializer.Serialize(textWriter, objCustomer);
string objresult = getXMLString(textWriter.ToString(), "customers");
StringReader XmlDeserializer = new StringReader(objresult);
return (customer)xmlSerializer.Deserialize(XmlDeserializer);
///return js.Deserialize(objresult);
}
}
public string getXMLString(string xmlContent, string url)
{
string Url;
string sResult;
Url = System.Configuration.ConfigurationManager.AppSettings["UserURl"] + url;
var httpWebRequest = (HttpWebRequest)WebRequest.Create(Url);
httpWebRequest.ContentType = "text/xml";
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
streamWriter.Write(xmlContent);
streamWriter.Flush();
streamWriter.Close();
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
sResult = result;
}
}
return sResult;
}
0 Comment(s)