Solved

asp.net 2.0 xml

Posted on 2014-11-08
1
340 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can Selenium do Load Testing? 2 61
asp.net repeater server posting 5 39
Left aligned $ and right aligned amount ASP.NET 7 45
Example code 13 45
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

752 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