下面是webservice的几个方法,把代码全贴出来了; using System; using System.ComponentModel; using System.Data; using System.Linq; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Xml.Linq; using System.Collections.Generic; using System.Collections; namespace AccountService { /// <summary> /// Service1 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ToolboxItem(false)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 // [System.Web.Script.Services.ScriptService] public class Service1 : System.Web.Services.WebService { /// <summary> /// 获取游戏服务器列表 /// </summary> /// <param name="strdata">游戏编码</param> /// <returns>服务器列表List </returns> [WebMethod] public string GetServerList(string gamecode) { try { if (string.IsNullOrEmpty(gamecode)) return null; WebCommon.ModelExtend.WebSiteGame game = WebCommon.DataSource.GetWebSiteGame(gamecode); List<Model.GameServerInfo> serverlist = game.ServerToList("->"); serverlist.Sort(Comparison); return Convert.ObjectToString (serverlist); } catch { return null; } } public int Comparison(Model.GameServerInfo x, Model.GameServerInfo y) { return x.ServerNameMain.CompareTo(y.ServerNameMain); } /// <summary> /// 获取帐号搜索条件 /// </summary> /// <param name="strdata">游戏编码</param> /// <returns>帐号配置条件</returns> [WebMethod] public string GetAccountConfig(string gamecode) { if (string.IsNullOrEmpty(gamecode)) return null; IList<Entity.AccountConfig> searchlist = WebCommon.AccountDataSource.AccountConfigSerachGet(gamecode); return Convert.ObjectToString (searchlist); } /// <summary> /// 查询帐号列表 /// </summary> /// <param name="pageindex">查询页索引</param> /// <param name="pagesize">一页显示多少</param> /// <param name="gameservercode">游戏服务器编码</param> /// <param name="faction">search faction</param> /// <param name="race">search race</param> /// <param name="accountclass">search class</param> /// <param name="level">search level</param> /// <returns></returns> [WebMethod] public string SearchAccountList(int pageindex,int pagesize,string gameservercode,string faction,string race,string accountclass,int level) { Arguments.AccountQuery query = new Arguments.AccountQuery(); if (pageindex >= 0) query.PageIndex = pageindex; else query.PageIndex = 0; if (query.PageSize > 0) query.PageSize = pagesize; else query.PageSize = 20; if (!string.IsNullOrEmpty(query.GameServerCode) && query.GameServerCode.Length > 3) query.GameServerCode = gameservercode; else query.GameCode = gameservercode; if (!string.IsNullOrEmpty(faction)) { if (query.Description != null && query.Description.Length > 0) query.Description += "%"; query.Description = faction; } if (!string.IsNullOrEmpty(race)) { if(query .Description!=null && query .Description .Length >0) query .Description +="%"; query.Description += race; } if (!string.IsNullOrEmpty(accountclass)) { if (query.Description != null && query.Description.Length > 0) query.Description += "%"; query.Description += accountclass; } if(level >0) query.Level = level; query.AccountSaleType = new int[] { (int)Arguments.Named.AccountSaleType.普通销售 }; int rcount = 0; IList<Entity.Account> list = WebCommon.AccountDataSource.AccountListGet(query, ref rcount); Dictionary<string, object> dic = new Dictionary<string, object>(); dic.Add("TotalPage", rcount); dic.Add("AccountList", list); return Convert.ObjectToString (dic); } /// <summary> /// 获取帐号详细信息 /// </summary> /// <param name="accountguid">帐号guid</param> /// <returns></returns> [WebMethod] public string GetAccountDetails(Guid accountguid) { if (accountguid == Guid.Empty) return null; Entity.Account account = WebCommon.AccountDataSource.AccountGet(accountguid); if (account != null) return Convert.ObjectToString(account); else return null; } /// <summary> /// 更新已卖掉的帐号 /// </summary> /// <param name="AccountRealId">帐号的真实ID</param> /// <returns>是否更新成功</returns> [WebMethod ] public bool UpdateAccountStatus(string AccountRealId) { if (string.IsNullOrEmpty(AccountRealId)) return false; bool result = WebCommon.AccountDataSource.AccountStatusUpdate(AccountRealId); return result; } } } 上面用到的Convert序列化处理类在本人空间已给出 下面是具体的调用 using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Collections.Generic; namespace test { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //获取游戏服务器 AccountService.Service1 service = new test.AccountService.Service1(); string strserver= service.GetServerList("013"); List<Model.GameServerInfo> serverlist = (List <Model.GameServerInfo >)Convert.StringToObject(strserver); //获取帐号查询条件 string strconfig = service.GetAccountConfig("013"); IList <Entity .AccountConfig>configlist=(IList <Entity .AccountConfig >)Convert .StringToObject (strconfig ); //获得帐号列表 string straccountlist = service.SearchAccountList(0, 20, "013", null, null,null,70); Dictionary <string,object >dic=(Dictionary <string,object >) Convert.StringToObject(straccountlist); int sumpage = (int)dic["TotalPage"]; IList<Entity.Account> accountlist = (IList<Entity.Account>)dic["AccountList"]; //获得帐号详细信息 if (accountlist != null && accountlist.Count > 0) { Entity.Account account =(Entity .Account )Convert .StringToObject( service.GetAccountDetails(accountlist[0].Guid)); //更新已卖帐号的状态 bool re = service.UpdateAccountStatus(account.RealID); Entity.Account nowaccount = (Entity.Account)Convert.StringToObject(service.GetAccountDetails(accountlist[0].Guid)); } } } }