项目是这样的:本网站中一个网页是记录一天出入人员信息的,现在想让这个网页可以被其他网站调用,该怎么做?
我老师说是用WebService,可我没学过,不知道怎么搞
------解决思路----------------------
简单的功能,只需用一般处理程序就可以了。
ashx够用的,可以接受get、post数据,可以将返回数据组织成json、xml、excle等等格式进行返回,也可以返回图片、压缩文件等等、总之Response.ContentType类型里支持都可以。不要单独再搞什么webservice。
在现有的项目里加一个ashx文件就行了。
------解决思路----------------------
[WebService(Namespace = "http://www.hy9909.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
/// <summary>
/// 用户登录验证(0:登录成功;1:用户名不存在;2:密码错误;3:帐号停用)
/// </summary>
/// <param name="LoginName">用户名</param>
/// <param name="LoginPWD">密码</param>
/// <returns></returns>
[WebMethod]
public string GetUserLogin(string LoginName,string LoginPWD)
{
try
{
string sql = " select * from IC_T_users where UserName='" + LoginName + "'";
DataTable dt = new DataTable();
dt = DbHelperSQL.GetDataTable(sql);
if (dt != null && dt.Rows.Count > 0)
{
sql = " select * from IC_T_users where UserName='" + LoginName + "' and Password='" + LoginPWD + "'";
dt = DbHelperSQL.GetDataTable(sql);
if (dt != null && dt.Rows.Count > 0)
{
if (dt.Rows[0]["Status"].ToString() == "0")
{
return "0";
}
else
{
return "3";
}
}
else
{
return "2";
}
}
else
{
return "1";
}
}
catch (Exception e)
{
return "404";
}
}
webservice的一个例子 ,它只能返回数据,如string,json,datatable,返回不了页面的