Web service to return xml file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TompIfe

    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



  • Steven Cheng

    #2
    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



    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(genera ted) via the
    Response.WriteF ile 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:
    msdnmg@microsof t.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" <tpskonto@commu nity.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




    Comment

    • Steven Cheng

      #3
      RE: Web service to return xml file

      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:
      msdnmg@microsof t.com.

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

      --------------------g: 7bit
      From: stcheng@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



      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(genera ted) via the
      Response.WriteF ile 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:
      msdnmg@microsof t.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" <tpskonto@commu nity.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






      Comment

      • Steven Cheng

        #4
        RE: Web service to return xml file

        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=localhos t;Initial
        Catalog=testdb; Integrated Security=True";
        string sqltxt = "select [id],[name] from edit_table";


        using (SqlConnection conn = new SqlConnection(c onnstr))
        {
        conn.Open();

        SqlCommand comm = new SqlCommand(sqlt xt, conn);

        IDataReader reader = comm.ExecuteRea der();

        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("outpu t.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@microsof t.com.


        --------------------
        From: "TompIfe" <tpskonto@commu nity.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








        Comment

        • TompIfe

          #5
          Re: Web service to return xml file

          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@online .microsoft.comw rote in message
          news:RoDAENTKJH A.4620@TK2MSFTN GHUB02.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=localhos t;Initial
          Catalog=testdb; Integrated Security=True";
          string sqltxt = "select [id],[name] from edit_table";
          >
          >
          using (SqlConnection conn = new SqlConnection(c onnstr))
          {
          conn.Open();
          >
          SqlCommand comm = new SqlCommand(sqlt xt, conn);
          >
          IDataReader reader = comm.ExecuteRea der();
          >
          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("outpu t.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@microsof t.com.
          >
          >
          --------------------
          From: "TompIfe" <tpskonto@commu nity.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
          >
          >
          >
          >
          >
          >
          >
          >

          Comment

          • Steven Cheng

            #6
            Re: Web service to return xml file

            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:
            msdnmg@microsof t.com.

            --------------------
            From: "TompIfe" <tpskonto@commu nity.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"" <stcheng@online .microsoft.comw rote in message
            news:RoDAENTKJH A.4620@TK2MSFTN GHUB02.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=localhos t;Initial
            Catalog=testdb; Integrated Security=True";
            string sqltxt = "select [id],[name] from edit_table";
            >
            >
            using (SqlConnection conn = new SqlConnection(c onnstr))
            {
            conn.Open();
            >
            SqlCommand comm = new SqlCommand(sqlt xt, conn);
            >
            IDataReader reader = comm.ExecuteRea der();
            >
            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())
            >

            Comment

            Working...