So I'm looking to try and serialize the results that my stream is returning. I'm working in .Net 4.
Currently working with the following in my home controller which is returning line by line the XML elements and the data within them.
HttpWebResponse response = null;
{
try
{
HttpWebRequest myrequest = (HttpWebRequest)WebRequest.Create(url);
string headerString = (username + ":" + password);
CredentialCache mycache = new CredentialCache();
mycache.Add(new Uri(url), "Basic", new NetworkCredential(username, password));
myrequest.Credentials = mycache;
myrequest.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(headerString)));
response = (HttpWebResponse)myrequest.GetResponse();
string responsetoken = response.GetResponseHeader("Token");
if (responsetoken.Length > 0)
{
// We have a token - use this for the next hour..
}
String status = response.StatusDescription;
Stream s = response.GetResponseStream();
StreamReader responseReader = new StreamReader(s);
// Now use XmlDocument and XmlReader to get the xml reponse.
// e.g. Create the reader from the stream and call xmldoc.Load(xmlreader);
XmlDocument xmldoc = new XmlDocument();
XmlReader reader = XmlReader.Create(responseReader);
while (reader.Read())
{
Console.WriteLine(reader.Value);
}
// read
{
}
}
What I need to do next is serialize the returned information from the stream so I can then write it to my database.
My set up already includes SOAP serialization from a SOAP feed (of course) but this is from a Web API and from what I've seen on Google so far is that XML serialization and SOAP serialization are handled differently.
So an example of how to serialize from this stream of data would be great as once I've got some serialized data strings I can then start looking at writing those to the database.
Thanks for any help guys.
No comments:
Post a Comment