在c# 服务端的Service.cs文件中写的接口,之前是供手机端解析调用的,但现在还想写一个网页的客户端,也是用c#写,可不可以在aspx.cs文件中直接调用这些接口?怎么调用,麻烦详细点说~~~接口类似这种: [WebMethod]
protected DataSet tip_details(string username)
{
SqlConnection sqlconnection = new SqlConnection(ConnectionString);
sqlconnection.Open();
string cmdstring = "select title,details,id,time from [tip] ";
SqlDataAdapter sqlAdapteruser = new SqlDataAdapter(cmdstring, sqlconnection);
DataSet ds = new DataSet();
sqlAdapteruser.Fill(ds, "tip");
sqlconnection.Close();
return ds;
}
[WebMethod ]
public DataSet send_tips(string username) //环保小贴士
{ DataSet ds = new DataSet(); ds = tip_details (username);
return ds; }
还有这种: [WebMethod]
public Boolean ValidLogin(string username, string password) //验证登陆名与密码是否匹配
{ Boolean flag = false;
SqlConnection sqlconnection = new SqlConnection(ConnectionString);
sqlconnection.Open();
string cmdcount="select count(username) from [user] where username=" + "'" + username + "'";
SqlCommand cmdd = new SqlCommand(cmdcount, sqlconnection);
int cc = (int)cmdd.ExecuteScalar();
if(cc==0)
return false;
string cmdString = "select password from [user] where username=" + "'" + username + "'";
SqlCommand cmd = new SqlCommand(cmdString, sqlconnection);
string pas = (string)cmd.ExecuteScalar();
sqlconnection.Close();
if ((pas.Trim() != password.Trim()) || pas.Trim () == null)
{ flag = false; }
else
{ flag = true; } return flag;
}
这样的接口文件要怎么直接调用?还有获取的东西还可不可以绑定在detailsview和gridview里了?
protected DataSet tip_details(string username)
{
SqlConnection sqlconnection = new SqlConnection(ConnectionString);
sqlconnection.Open();
string cmdstring = "select title,details,id,time from [tip] ";
SqlDataAdapter sqlAdapteruser = new SqlDataAdapter(cmdstring, sqlconnection);
DataSet ds = new DataSet();
sqlAdapteruser.Fill(ds, "tip");
sqlconnection.Close();
return ds;
}
[WebMethod ]
public DataSet send_tips(string username) //环保小贴士
{ DataSet ds = new DataSet(); ds = tip_details (username);
return ds; }
还有这种: [WebMethod]
public Boolean ValidLogin(string username, string password) //验证登陆名与密码是否匹配
{ Boolean flag = false;
SqlConnection sqlconnection = new SqlConnection(ConnectionString);
sqlconnection.Open();
string cmdcount="select count(username) from [user] where username=" + "'" + username + "'";
SqlCommand cmdd = new SqlCommand(cmdcount, sqlconnection);
int cc = (int)cmdd.ExecuteScalar();
if(cc==0)
return false;
string cmdString = "select password from [user] where username=" + "'" + username + "'";
SqlCommand cmd = new SqlCommand(cmdString, sqlconnection);
string pas = (string)cmd.ExecuteScalar();
sqlconnection.Close();
if ((pas.Trim() != password.Trim()) || pas.Trim () == null)
{ flag = false; }
else
{ flag = true; } return flag;
}
这样的接口文件要怎么直接调用?还有获取的东西还可不可以绑定在detailsview和gridview里了?
{
if (classname == null || classname == "")
{
classname = WebServiceHelper.GetClassName(url);
}
//获取服务描述语言(WSDL)
WebClient wc = new WebClient();
Stream stream = wc.OpenRead(url + ComUtil.WSDL);//【1】
ServiceDescription sd = ServiceDescription.Read(stream);//【2】
ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();//【3】
sdi.AddServiceDescription(sd, "", "");
CodeNamespace cn = new CodeNamespace(WebServiceNS);//【4】 //生成客户端代理类代码
CodeCompileUnit ccu = new CodeCompileUnit();//【5】
ccu.Namespaces.Add(cn);
sdi.Import(cn, ccu);
CSharpCodeProvider csc = new CSharpCodeProvider();//【6】
ICodeCompiler icc = csc.CreateCompiler();//【7】 //设定编译器的参数
CompilerParameters cplist = new CompilerParameters();//【8】
cplist.GenerateExecutable = false;
cplist.GenerateInMemory = true;
cplist.ReferencedAssemblies.Add("System.dll");
cplist.ReferencedAssemblies.Add("System.XML.dll");
cplist.ReferencedAssemblies.Add("System.Web.Services.dll");
cplist.ReferencedAssemblies.Add("System.Data.dll"); //编译代理类
CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);//【9】
if (true == cr.Errors.HasErrors)
{
System.Text.StringBuilder sb = new StringBuilder();
foreach (CompilerError ce in cr.Errors)
{
sb.Append(ce.ToString());
sb.Append(System.Environment.NewLine);
}
throw new Exception(sb.ToString());
} //生成代理实例,并调用方法
System.Reflection.Assembly assembly = cr.CompiledAssembly;
Type t = assembly.GetType(WebServiceNS + "." + classname, true, true);
object obj = Activator.CreateInstance(t);//【10】
System.Reflection.MethodInfo mi = t.GetMethod(methodname);//【11】 return mi.Invoke(obj, args);
}