ITsolutionWizard
asked on
asp.net 2.0 xml
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(Conform sTo = WsiProfiles.BasicProfile1_ 1)]
[System.ComponentModel.Too lboxItem(f alse)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Service s.ScriptSe rvice]
public class WebService : System.Web.Services.WebSer vice
{
[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;Integ rated Security=True";
SqlConnection dbConnection = null;
// Open a connection to the database
try
{
dbConnection = new SqlConnection(connectionSt ring);
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.ExecuteXmlR eader())
{
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(upl oadPath))
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<root>" + myDatas + "</root>");
doc.PreserveWhitespace = true;
doc.Save(uploadPath + defaultXmlFileName);
}
}
#endregion
if (passCode != "abc")
{
myDatas = null;
}
return myDatas;
}
}
}
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(Conform
[System.ComponentModel.Too
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Service
public class WebService : System.Web.Services.WebSer
{
[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;Integ
SqlConnection dbConnection = null;
// Open a connection to the database
try
{
dbConnection = new SqlConnection(connectionSt
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.ExecuteXmlR
{
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(upl
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<root>" + myDatas + "</root>");
doc.PreserveWhitespace = true;
doc.Save(uploadPath + defaultXmlFileName);
}
}
#endregion
if (passCode != "abc")
{
myDatas = null;
}
return myDatas;
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.