Created
July 26, 2010 21:13
-
-
Save hyrmn/491261 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string xmlString = SerializeResultsToXmlString(response); | |
return Content(xmlString, "application/xml", Encoding.UTF8); | |
private string SerializeResultsToXmlString(ApiResponse response) | |
{ | |
var memoryStream = new MemoryStream(); | |
var xs = new XmlSerializer(typeof(ApiResponse)); | |
var xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8); | |
xs.Serialize(xmlTextWriter, response); | |
memoryStream = (MemoryStream)xmlTextWriter.BaseStream; | |
return UtfByteArrayToString(memoryStream.ToArray()); | |
} | |
private static String UtfByteArrayToString(Byte[] characters) | |
{ | |
var encoding = new UTF8Encoding(); | |
return encoding.GetString(characters); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment