How can I return xml from a webservice instead of a dataset?

wildbrookmedia
wildbrookmedia used Ask the Experts™
on
I am trying to load my data that I get from the db as a dataset into xml so i can return it and work with it in Flash.  How can I do this?  (it is a webservice)

[WebMethod(Description = "Return all employees in the database as xml.")]
    public XmlDocument GetAllPeopleRelXML()
    {
        ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings["EmployeeConnectionString"];
        string constring = setting.ConnectionString;

        dsEmployee ds = new dsEmployee();
        SqlConnection conn = new SqlConnection(constring);

        conn.Open();

        dsEmployeeTableAdapters.spSelPersonAllRelTableAdapter personDA = new dsEmployeeTableAdapters.spSelPersonAllRelTableAdapter();

        personDA.Connection = conn;
        personDA.Fill(ds.spSelPersonAllRel);
        XmlDataDocument datadoc = new XmlDataDocument();
        ds.WriteXml(datadoc);

        return datadoc;
    }
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2008
Commented:
Try this:

using System.IO;
using System.Text;

    [WebMethod(Description = "Return all employees in the database as xml.")]
    public string GetAllPeopleRelXML()
    {

        ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings["EmployeeConnectionString"];
        string constring = setting.ConnectionString;

        dsEmployee ds = new dsEmployee();
        using (SqlConnection conn = new SqlConnection(constring))
        {
            conn.Open();

            dsEmployeeTableAdapters.spSelPersonAllRelTableAdapter personDA = new dsEmployeeTableAdapters.spSelPersonAllRelTableAdapter();

            personDA.Connection = conn;
            personDA.Fill(ds.spSelPersonAllRel);
            StringBuilder sb = new StringBuilder();
            using (StringWriter writer = new StringWriter(sb))
            {
                ds.WriteXml(writer);
            }
            return sb.ToString();
        }
        return "";
    }
 
Bob

Author

Commented:
Cool, thank you for that.  Do you know if this is slower in working with the data in flash as opposed to returning an array of items or anything?  I haven't found a way to work directly with the dataset so I think converting it to xml like you did above will have to be the way to go...
Most Valuable Expert 2012
Top Expert 2008

Commented:
It depends on what you are trying to serialize and deserialize with SOAP to process the web requests.  It is difficult to say with any certainty without understanding the entire problem space in more detail.

Bob
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
For now I am just playing with writing webservices in C# and playing with them in flash.  What I am trying to do is write a front end application for a family history web service that I have added a few methods too.

ex here:
http://blogs.msdn.com/coding4fun/archive/2006/10/31/913303.aspx

For the end product I would like to be able to view all family members, update, add, and search for them through the flash interface.

Author

Commented:
Closed it as you answered my question and I was getting off topic...

Author

Commented:
thanks again for the quick reply though!

Author

Commented:
Does your method return a true xml doc or a string that has the format of an xml doc?  I wrote some code in Flash to consume the xml doc but it doesnt seem to recognize it as xml...

Thanks!  

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial