Re: Web service to return xml file
- From: "TompIfe" <tpskonto@xxxxxxxxxxxxxxxx>
- Date: Thu, 9 Oct 2008 15:42:39 +0200
Hi Steven,
I have used your code example to create web methods that return xml files,
and they work perfectly fine.
Thank you for your assistance,
Tom Pedersen
""Steven Cheng"" <stcheng@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:RoDAENTKJHA.4620@xxxxxxxxxxxxxxxxxxxxxxxxx
Hi Tom,
Nice to hear from you.
AS for LINQ to XML, it can help conveniently generated xml document from a
certain object collection together with LINQ to object. Are you using
VB.NET or c#(vb.net has provided more advanced support on LINQ to XML).
Here I use a SQLServer data accessing case t demonstrate (should be the
same code logic for Access Database). I use datareader to retrieve data
and LINQ to XML to compose the XML document from the data:
=============================
private static void Run_LINQ()
{
string connstr = "Data Source=localhost;Initial
Catalog=testdb;Integrated Security=True";
string sqltxt = "select [id],[name] from edit_table";
using (SqlConnection conn = new SqlConnection(connstr))
{
conn.Open();
SqlCommand comm = new SqlCommand(sqltxt, conn);
IDataReader reader = comm.ExecuteReader();
XDocument doc = new XDocument();
XElement root = new XElement("root");
while (reader.Read())
{
root.Add(
new XElement("Item",
new XElement("id", reader["id"].ToString()),
new XElement("name",reader["name"].ToString())
)
);
}
reader.Close();
doc.Add(root);
doc.Save("output.xml");
}
}
=====================================
You can see that LINQ to XML code somewhat make the xml document/element
generation more visualized/readable.
If you have any further question, welcome to let me know. I'll also update
you in the newsgroup.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@xxxxxxxxxxxxxx
--------------------
From: "TompIfe" <tpskonto@xxxxxxxxxxxxxxxx>
Subject: Web service to return xml file
Date: Mon, 29 Sep 2008 10:48:41 +0200
Hi,
I have a web service that reads data from an Access database using
datareader and place the data in an array that
the web method returns.
Now, I want to make the web service also to return an xml file with the
data.
How do I best proceed?
Best regards,
Tom
.
- Follow-Ups:
- Re: Web service to return xml file
- From: "Steven Cheng"
- Re: Web service to return xml file
- References:
- RE: Web service to return xml file
- From: "Steven Cheng"
- RE: Web service to return xml file
- From: "Steven Cheng"
- RE: Web service to return xml file
- Prev by Date: Re: Consumming a WebService in the same time
- Next by Date: WCF Security: How restrict an endpoint to only response to a given windows user or group?
- Previous by thread: RE: Web service to return xml file
- Next by thread: Re: Web service to return xml file
- Index(es):
Relevant Pages
|