【IT168技术文档】
1:建立VS2005 WebService项目
代码中序列化自定义类
撰写Webservice方法:[Serializable] public struct UserInfo{ public string username; public string password; };
[WebMethod] public UserInfo GetAUserByID(string username) { UserInfo ui = new UserInfo(); string sql = "select username,password from UserInfo where username='"; sql += username; sql += "'"; try { sqlConnection.Open(); //SQLCMD.CommandText = sql; SqlDataAdapter adapter = new SqlDataAdapter(sql,sqlConnection); //adapter = SQLCMD.ExecuteReader(); DataSet ds = new DataSet(); adapter.Fill(ds); ui.username = ds.Tables[0].Rows[0]["username"].ToString(); ui.password = ds.Tables[0].Rows[0]["password"].ToString(); //sda. } catch { } finally { sqlConnection.Close(); } return ui; }