Example #1
0
        public HttpResponseMessage GetText()
        {
            string filePath = Func.GetFileName();
            string fileContent = File.ReadAllText(filePath);
            Text text = Parser.ParseInputText(fileContent);

            var xml = new XMLFormatter();

            var content = new ObjectContent<Text>(
                text,										// What we are serializing
                xml,									// The media formatter
                // display result as xml document
                new MediaTypeHeaderValue("application/xml")	// The media formatter
                );

            return new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content = content,
            };
        }
Example #2
0
        public void TestXMLFormatterSerialize()
        {
            string fileContent = File.ReadAllText("output.txt");
            Assert.IsNotNull(fileContent, "File is empty");
            Text text = Parser.ParseInputText(fileContent);

            FileStream fs = new FileStream("output.xml", FileMode.Create);
            var xml = new XMLFormatter();

            var content = new ObjectContent<Text>(
            text,							// What we are serializing
            xml//,						// The media formatter
                //mediaTypeHeaderValue.MediaType	// The MIME type
            );
            xml.WriteToStreamAsync(typeof(Text), text, fs, content, null);
        }