using System.Net.Http;
using Newtonsoft.Json;
using System.Text;
using System.Runtime.Serialization.Json;
这里需要添加一些资源库进去,然后引用。
分别是System.Net.Http.dll Newtonsoft.Json.dll。
下面举一个接口的例子:
[WebMethod(Description = "核实登录信息")]
public string WebLogin(string username, string pass)
{
ResponseMessage rs = new ResponseMessage();
try
{
string ConnStr = "server=lz-bjb;database='jzclk';uid='sa';pwd='sadhslzlz';";
SqlConnection sqlConn = new SqlConnection(ConnStr);
sqlConn.Open();
string sqlSel = "select count(*) from tb_md where [工号]='" + username + "' and [密码]='" +
pass + "'";
SqlCommand sqlcom = new SqlCommand(sqlSel, sqlConn);
int i = Convert.ToInt32(sqlcom.ExecuteScalar());
sqlConn.Close();
if (i == 1)
{
string sqlSel1 = "select 姓名,部门,权限 from tb_md where [工号]='" + username + "' and [密
码]='" + pass + "'";
SqlDataAdapter da = new SqlDataAdapter(sqlSel1, sqlConn);
DataSet ds = new DataSet();
da.Fill(ds, "tb_md");
DataRowView drv = ds.Tables["tb_md"].DefaultView[0];
string name = Convert.ToString(drv.Row["姓名"]);
string bm = Convert.ToString(drv.Row["部门"]);
string qx = Convert.ToString(drv.Row["权限"]);