1.webservice的使用
[WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 [System.Web.Script.Services.ScriptService] public class UserService : System.Web.Services.WebService { private UserDAO userDAO = new UserDAO(); [WebMethod(Description="登陆")] public UserInfo GetUser(string name, string pwd) { UserDAO userDAO = new UserDAO(); UserInfo user = userDAO.GetUser(name, pwd); return user; } }
2.返回DataTable时,必须制定表的名字,否则会报错
[WebMethod] public string GetUsersXML() { string sql = "select * from userInfo"; DataTable dt = DbHelper.GetDataTable(sql, null); dt.TableName = "usersTable"; string xmlStr = ""; try { xmlStr = XmlDataTablUtil.TableToXML(dt); } catch (Exception e) { } return xmlStr; }
3.客户端通过添加web引用可以直接调用webservice的方法