user1720624
user1720624

Reputation:

Webservice returns only System.Xml.XmlDocument string

When I call my webservice, it only returns the string "System.Xml.XmlDocument" rather than the actual XML. What do I need to change to get it to return an actual XML document?

 public XmlDocument GetCommoditiesXmlDocument() {
            XmlDocument xdoc = new XmlDocument();
            StringWriter sw = new StringWriter();
            XmlTextWriter xtw = new XmlTextWriter(sw);

            //gets XML as XmlElement

            quotes.WriteTo(xtw);
            xdoc.LoadXml(sw.ToString());
            return xdoc;
        }

I'm using .NET 4.0 (and MVC3 if it matters)

Upvotes: 1

Views: 838

Answers (1)

SLaks
SLaks

Reputation: 887443

ASP.Net MVC does not know how to serialize an XmlDocument into an HTTP response.

Instead, you should return the XML source directly:

return Content(sw.ToString(), "text/xml");

Upvotes: 2

Related Questions