您的位置:首页 > 其它

调用WCF服务

2015-03-21 22:17 127 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace SilverlightApplication1.Web
{
// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、svc 和配置文件中的类名“DBServices”。
// 注意: 为了启动 WCF 测试客户端以测试此服务,请在解决方案资源管理器中选择 DBServices.svc 或 DBServices.svc.cs,然后开始调试。
public class DBServices : IDBServices
{
private SqlConnection pSqlConn = null;
private string sSqlConnString = "Data Source=ZHANGJIE-PC;Initial Catalog=yzx-1;Integrated Security=True";
public void DoWork()
{
}
public bool CheckUser(string sUser, string sPsd)
{
try
{
//连接数据库
if (CheckSQLConn())
{
string sql = "select * from dbo.yzx where 用户名='{0}' and 密码='{1}'";
sql = String.Format(sql, sUser, sPsd);
// 查询数据库里面的记录
SqlDataAdapter pSQLDataAdapter = new SqlDataAdapter(sql, pSqlConn);
DataSet pDataSet = new DataSet();

pSQLDataAdapter.Fill(pDataSet);

int ResultCount = pDataSet.Tables[0].Rows.Count;
//判断该记录是否存在
if (ResultCount > 0)
{
return true;
}
else
{
return false;
}
}
return false;
}
catch
{
return false;
}

}

/// <summary>
/// 连接数据库
/// </summary>
/// <returns></returns>
private bool CheckSQLConn()
{
try
{
//判断连接是否存在
if (pSqlConn == null)
{
pSqlConn = new SqlConnection();
pSqlConn.ConnectionString = sSqlConnString;
}
//判断连接有没有开启
if (pSqlConn.State != ConnectionState.Open)
{
pSqlConn.Open();
}
return true;
}
catch
{
return false;
}

}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: