467,915 Members | 1,823 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,915 developers. It's quick & easy.

Web service to return xml file

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

Sep 29 '08 #1
  • viewed: 4883
Share:
5 Replies
Hi tomplfe,

From your description, I understand that you're developing a webservice
which read data from an Access database and return the data back to
webservice client. You're currently wondering how to make the data return
as an XML Document, correct?

Regarding on the problem, I think there are two main sub problems here:

1. How do we generate the XML document/xml format data based on the record
retrieved from the Access database

2. How do we return such an generated XML Document in webservice to client

Which one are you currently focus on or are you struggling on both of them?

IMO, for the two issues, you can consider the following approaches:

1. As for generating xml document, if your webservice use .NET 3.5, then I
strongly recommend you use LINQ to XML since it extremely simplify the XML
document generation and processing.

#Creating XML Trees
http://msdn.microsoft.com/en-us/library/bb387068.aspx

http://weblogs.asp.net/scottgu/archi...o-xml-and-how-
to-build-a-custom-rss-feed-reader-with-it.aspx

If LINQ to XML is not usable, you may need to manually use System.Xml
namespace's API or .NET xml serialization to generate the XML document.

2. For return the XML document/file to webservice client. You can directly
define your webservice's return type as XmlDocument and return the
generated Xml Document out. Do not use string type , that 's not correct.

Or you can even setup a simple ASP.NET httphandler which accept some
querystring as parameter and return the XML document(generated) via the
Response.WriteFile or Response.Write and set page's Contenttype as
text/xml.

How do you think?

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:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/...tance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
From: "TompIfe" <tp******@community.nospam>
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


Sep 30 '08 #2
Hi tomplfe,

How are you doing?

Have you got any progress on this issue or does the suggestion in my last
reply help you some? If you still have any question on this, welcome to
post here.

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:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

--------------------g: 7bit
From: st*****@online.microsoft.com ("Steven Cheng")
Organization: Microsoft
Date: Tue, 30 Sep 2008 03:59:31 GMT
Subject: RE: Web service to return xml file

Hi tomplfe,

From your description, I understand that you're developing a webservice
which read data from an Access database and return the data back to
webservice client. You're currently wondering how to make the data return
as an XML Document, correct?

Regarding on the problem, I think there are two main sub problems here:

1. How do we generate the XML document/xml format data based on the record
retrieved from the Access database

2. How do we return such an generated XML Document in webservice to client

Which one are you currently focus on or are you struggling on both of them?

IMO, for the two issues, you can consider the following approaches:

1. As for generating xml document, if your webservice use .NET 3.5, then I
strongly recommend you use LINQ to XML since it extremely simplify the XML
document generation and processing.

#Creating XML Trees
http://msdn.microsoft.com/en-us/library/bb387068.aspx

http://weblogs.asp.net/scottgu/archi...o-xml-and-how-
to-build-a-custom-rss-feed-reader-with-it.aspx

If LINQ to XML is not usable, you may need to manually use System.Xml
namespace's API or .NET xml serialization to generate the XML document.

2. For return the XML document/file to webservice client. You can directly
define your webservice's return type as XmlDocument and return the
generated Xml Document out. Do not use string type , that 's not correct.

Or you can even setup a simple ASP.NET httphandler which accept some
querystring as parameter and return the XML document(generated) via the
Response.WriteFile or Response.Write and set page's Contenttype as
text/xml.

How do you think?

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:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/...tance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
From: "TompIfe" <tp******@community.nospam>
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


Oct 2 '08 #3
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:
ms****@microsoft.com.
--------------------
From: "TompIfe" <tp******@community.nospam>
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


Oct 8 '08 #4
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"" <st*****@online.microsoft.comwrote in message
news:Ro**************@TK2MSFTNGHUB02.phx.gbl...
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:
ms****@microsoft.com.
--------------------
From: "TompIfe" <tp******@community.nospam>
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




Oct 9 '08 #5
Thanks for your reply Tom,

I'm glad that the suggestion helps you. If you encounter any further issues
or need any help later, please feel free to let me know.

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:
ms****@microsoft.com.

--------------------
From: "TompIfe" <tp******@community.nospam>
Subject: Re: Web service to return xml file
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"" <st*****@online.microsoft.comwrote in message
news:Ro**************@TK2MSFTNGHUB02.phx.gbl...
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())
Oct 10 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

18 posts views Thread by jabailo | last post: by
3 posts views Thread by Doug Bailey | last post: by
1 post views Thread by Alan Sloan | last post: by
20 posts views Thread by =?Utf-8?B?cmtibmFpcg==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.