|
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Runtime.InteropServices;
using System.Data.SqlClient;
using System.Configuration;
using System.Diagnostics;
using System.Data;
using System.Xml;
[WebService(Namespace = "http://localhost:2034/WebServices/", Description="This is my First WebServices Demo - By Vivek")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string DisplayTextMsg()
{
return "My First Service For Testing";
}
[WebMethod]
public string Vivek()
{
return "My Name is Vivek.T";
}
[WebMethod]
public XmlDocument GetDataFromDB()
{
string errorMessage = "";
XmlDocument myDatas = new XmlDocument();
//Connection string is stored in the web.config file as an appSetting
string connectionString = ConfigurationSettings.AppSettings["DatabaseConnectionString"];
SqlConnection dbConnection = null;
// Open a connection to the database
try
{
dbConnection = new SqlConnection(connectionString);
dbConnection.Open();
}
catch (Exception ex)
{
errorMessage = ex.Message;
}
if (errorMessage == "")
{
// Build an insert command
string SQL = "select * From ProfileContact";
SqlCommand GetCustomerCmd = new SqlCommand(SQL, dbConnection);
try
{
SqlDataAdapter custDA = new SqlDataAdapter();
custDA.SelectCommand = GetCustomerCmd;
DataSet custDS = new DataSet();
custDA.Fill(custDS, "ProfileContact");
myDatas.LoadXml(custDS.GetXml());
dbConnection.Close();
}
catch (System.Exception ex)
{
errorMessage = ex.Message;
}
finally
{
dbConnection.Dispose();
}
}
return myDatas;
}
//end
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.