📄 dataservice.cs
字号:
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.OleDb;
using kmdsoft.Database;
using kmdsoft.Security;
using kmdsoft.Web.Services;
using System.IO;
namespace kmdsoft.Services
{
[WebService(Namespace = "http://www.kmdsoft.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class DataService : System.Web.Services.WebService
{
//WebService身份验证的SOAP头的实例
public AuthenticationHeader Authentication;
public DataService()
{
String strConn = System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString");
WriteLog(strConn);
}
private void WriteLog(string strLog)
{
//实例化一个文件流--->与写入文件相关联
string sfile = "c:\\database.txt";
FileStream fs = new FileStream(sfile, FileMode.Create);
//实例化一个StreamWriter-->与fs相关联
StreamWriter sw = new StreamWriter(fs);
//开始写入
sw.Write(strLog);
//清空缓冲区
sw.Flush();
//关闭流
sw.Close();
fs.Close();
}
#region 邓资华
#region 身份验证处理
[WebMethod(MessageName = "AuthenticateByAuthenticationHeader")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public bool Authenticate()
{
//Context.Request.SaveAs("D:\\soapInfo.txt", true);
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
return this.AuthenticateUser(Authentication.UserName, Authentication.Password);
}
[WebMethod(Description="身份认证服务。")]
public bool AuthenticateUser(String account, String password)
{
try {
if (account == null || account.Trim().Length == 0)
throw new ArgumentNullException("Account");
if (password == null || password.Trim().Length == 0)
throw new ArgumentNullException("Password");
OleDbConnection conn = DataEngine.getConn();
if (conn==null)
throw new AuthenticationException(AuthenticationReason.Unknown);
IDbCommand command = conn.CreateCommand();
command.CommandText = "SELECT account,userpassword FROM user_quar WHERE account = '" + account + "'";
command.Connection.Open();
IDataReader reader = command.ExecuteReader();
if (!reader.Read())
throw new AuthenticationException(AuthenticationReason.InvalidAccount);
object userpassword = reader["userpassword"];
//可以加入MD5或者散列值判断。
if (!userpassword.Equals(password))
throw new AuthenticationException(AuthenticationReason.InvalidPassword);
command.Connection.Close();
return true;
}
catch (Exception ex)
{
throw SoapUtility.WrapException(ex, Context.Request.Url);
}
}
[WebMethod(Description = "获得认证后的用户实体信息!")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public DataSet GetUserBean(string account) {
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
DataPopeManage dp = new DataPopeManage();
return dp.GetUserBean(account);
}
#endregion
#region 测试方法
[WebMethod(Description="SayHello,此服务需要Soap报头认证")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public string HelloWorld(String name)
{
if (!this.Authenticate())
return null;
return "Hello World:" + name;
}
[WebMethod(Description = "测试数据连接。此服务需要Soap报头认证")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public String testConn() {
if (!this.Authenticate())
return null;
OleDbConnection conn = DataEngine.getConn();
return "当前连接:"+conn.ConnectionString;
}
#endregion
#region 人员管理
[WebMethod(Description = "查询“人员管理”,返回某个或全部人员信息。")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public DataSet user_quar_getinfo(string idclient)
{
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
ManManage obj = new ManManage();
return obj.user_quar_getinfo(idclient);
}
[WebMethod(Description = "查询“人员管理”,返回满足条件的人员信息。")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public DataSet user_quar_getlist(string strRgn, string strName)
{
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
ManManage obj = new ManManage();
return obj.user_quar_getlist(strRgn,strName);
}
[WebMethod(Description = "请求“删除数据”。成功返回真,失败返回假。")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public bool user_quar_delInfo(string idclient)
{
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
ManManage obj = new ManManage();
return obj.user_quar_delInfo(idclient);
}
[WebMethod(Description = "保存“人员管理”的数据。")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public bool user_quar_set(DataSet mDataSet)
{
//Context.Request.SaveAs("D:\\test\\soapInfo.txt", true);
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
ManManage obj = new ManManage();
return obj.user_quar_set(mDataSet);
}
#endregion
#endregion
#region 赵磊。
#region 行政区划
[WebMethod(Description = "查询“行政区划”,返回一条行政区划信息。")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public DataSet rgn_sys_getinfo(string rgn_code)
{
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
//生成查询条件
string strCom;
if (rgn_code != "")
{ strCom = " SELECT * FROM rgn_sys where rgn_code = '" + rgn_code + "'"; }
else
{
strCom = "SELECT * FROM rgn_sys where rgn_code is null";
}
DataEngine de = new DataEngine();
return de.query_database(strCom, "rgn_sys");
}
[WebMethod(Description = "查询“行政区划”,返回一条行政区划信息。")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public DataSet admini_area_getinfo(string usertoken, string rgncode)
{
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
string strCom;
if (rgncode != "")
{
strCom = " SELECT * FROM admini_area where code = '" + rgncode + "'";
}
else
{
strCom = " SELECT * FROM admini_area where code is null";
}
DataEngine de = new DataEngine();
return de.query_database(strCom, "admini_area");
}
[WebMethod(Description = "查询“行政区划”,返回满足条件的行政区划信息。")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public DataSet admini_area_getlist(string usertoken, string rgncode, string nLevel)
{
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
string strCom = "SELECT * FROM admini_area";
if (rgncode != "")
strCom = "SELECT * FROM admini_area where left(code," + rgncode.Length + ")='" + rgncode + "' and area_class='" + nLevel + "'";
DataEngine de = new DataEngine();
return de.query_database(strCom, "admini_area");
}
[WebMethod(Description = "请求“删除数据”。成功返回真,失败返回假。")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public bool admini_area_delInfo(string rgncode)
{
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
DataEngine de = new DataEngine();
rgncode="'"+rgncode+"'";
return de.del_database("code", rgncode, "admini_area");
}
[WebMethod(Description = "保存“行政区划”的数据。")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public bool admini_area_set(string usertoken, DataSet mDataSet)
{
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
DataEngine DE = new DataEngine();
int flag = DE.save_database(mDataSet, "admini_area");
if (flag == 1)
{
return true;
}
return false;
}
[WebMethod(Description = "查询“行政区划”,返回满足条件的行政区划信息。")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public string admini_area_getliststring(string usertoken, string rgncode, string nLevel)
{
//if (Authentication == null)
////throw new AuthenticationException(AuthenticationReason.Unlogin);
string strCom = "SELECT * FROM admini_area";
if (rgncode != "")
strCom = "SELECT * FROM admini_area where left(code," + rgncode.Length + ")='" + rgncode + "' and area_class=" + nLevel;
return strCom;
}
[WebMethod(Description = "在空间信息中查询“区划信息”,返回一条区划空间信息。")]
[SoapHeader("Authentication", Direction = SoapHeaderDirection.In)]
public DataSet rgn_getinfoFromMap(string usertoken, string id) //rgn_getinfoFromMap
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -