Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

asp.net 2.0 xml

Posted on 2014-11-08
1
Medium Priority
?
355 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 45

Accepted Solution

by:
AndyAinscow earned 2000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Screencast - Getting to Know the Pipeline
Suggested Courses

916 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