Solved

asp.net 2.0 xml

Posted on 2014-11-08
1
339 Views
Last Modified: 2014-11-20
Below web service codes are working fine. But I forgot I can only use .net framework 2.0.
And if I take out using System.xml.linq the code will break because it uses Xelement and Xdocument, and etc.

Unfortuneately, I have to stay in framework 2.0 and anyone knows how to modify below codes working with .net framework 2.0?

Thanks

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Configuration;
using System.Xml;
using System.Xml.Linq;

namespace WebApplication12
{
    /// <summary>
    /// Summary description for WebService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    // [System.Web.Script.Services.ScriptService]
    public class WebService : System.Web.Services.WebService
    {      
        [WebMethod]
        public string GetCoachList(Boolean isUpload, string uploadPath, int? locationID, string passCode)
        {

            string errorMessage = "";
            string myDatas = "";
            string defaultXmlFileName = "test.xml";

            //Connection string is stored
            //in the web.config file as an appSetting
            string connectionString = "Data Source=LENOVO-PC;Initial Catalog=DatabaseName;Integrated Security=True";
            SqlConnection dbConnection = null;
            // Open a connection to the database
            try
            {
                dbConnection = new SqlConnection(connectionString);
                dbConnection.Open();
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }
            if (errorMessage == "")
            {
                   string SQL = "SELECT * from test";
                SqlCommand GetCustomerCmd = new SqlCommand(SQL, dbConnection);
                try
                {
                    XDocument results = new XDocument(new XElement("results"));
                    using (XmlReader reader = GetCustomerCmd.ExecuteXmlReader())
                    {
                        reader.Read();
                        while (!reader.EOF)
                        {
                            myDatas = myDatas + reader.ReadOuterXml();
                        }                        
                    }
                    dbConnection.Close();
                }
                catch (System.Exception ex)
                {
                    errorMessage = ex.Message;
                }
                finally
                {
                    dbConnection.Dispose();
                }
            }

            #region do you want load and save the document?
            if (isUpload == true)
            {
                if (!string.IsNullOrEmpty(uploadPath))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml("<root>" + myDatas + "</root>");
                    doc.PreserveWhitespace = true;
                    doc.Save(uploadPath + defaultXmlFileName);
                }
            }
            #endregion

            if (passCode != "abc")
            {
                myDatas = null;
            }
            return myDatas;
        }
    }
}
0
Comment
Question by:ITsolutionWizard
1 Comment
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 40430439
>>Unfortuneately, I have to stay in framework 2.0 and anyone knows how to modify below codes working with .net framework 2.0?

Major rewriting to remove anything that depends on a newer framework OR really ask why you have to use such an old framework.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question