473,406 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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
5 5152
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: jabailo | last post by:
I wrote a program that loops through a file of records. It parses each line in the file and sends them to a web service that inserts them into an AS400DB2 database using Asynch calls. This is...
5
by: SP | last post by:
Please advice. I am not familiar with the concepts of windows service. I am trying to access a xml configuration file from windows service. But it is failing. configuration file is in the same...
0
by: Seth | last post by:
For some reason my service works fine except that it will create the file in my c drive, but will not write to the file. Sorry if this is a duplicate post, i have found some that ask the same...
3
by: Doug Bailey | last post by:
I am trying to control a Windows Service via a Web Service interface. (I am developing in .NET2003) I am using the ServiceController object which allows me to read the state of the services with...
4
by: kkt49 | last post by:
# vim: et sw=4 ts=8 sts from wxPython.wx import * import sys, os, time import pywintypes import win32serviceutil import win32service import win32event import win32process
4
by: rikleo2001 | last post by:
Hello Experts. I need your help, I am new to XML web service, and I have to complete one task. Here is current situation. 1. I have web service running to recieve SOAP message from an...
1
by: Alan Sloan | last post by:
I have written a Web Service that interacts with a COM component to extract a file from another system. Basically the Web Service accepts a part number and a rev and extracts the file to a...
20
by: =?Utf-8?B?cmtibmFpcg==?= | last post by:
I was executing the steps given in http://suppor.microsoft.com/kb/308359 for testing a sample web service application. However, the following line gives a compilation error: localhost.Service1...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.