WebService为手机开发提供服务

首先给出架构图:

iWS.BPDI.MobilePortal.BLL类中部分方法

/// <summary>
/// 获取通讯录
/// </summary>
/// <param name="UserName"></param>
/// <param name="UserPassword"></param>
/// <returns></returns>
public DataSet GetAddressList(string UserName, string UserPassword)
{
string Url = Functions.GetAppSeetingValueByKey(SysNames.P_WEB_URL);
#region 1、创建基本数据结构

DataSet ds = new DataSet("AddressList");

//通讯录信息
DataTable dt = new DataTable("List");

//工号
dt.Columns.Add("ID", typeof(string));
//员工姓名
dt.Columns.Add("Name", typeof(string));
//岗位
dt.Columns.Add("Job", typeof(string));
//部门
dt.Columns.Add("Department", typeof(string));
//分机
dt.Columns.Add("Extension", typeof(string));
//直拨电话
dt.Columns.Add("Phone", typeof(string));
//移动电话
dt.Columns.Add("MobilePhone", typeof(string));
//电子邮件
dt.Columns.Add("Email", typeof(string));
//区域
dt.Columns.Add("Area", typeof(string));
//房间号
dt.Columns.Add("RoomNub", typeof(string));

#endregion

using (ClientContext client = new ClientContext(Url))
{
NetworkCredential credentials = new NetworkCredential(UserName, UserPassword, Functions.GetAppSeetingValueByKey(SysNames.P_DOMAIN_NAME));
client.Credentials = credentials;
Web web = client.Web;
client.Load(web);//必须加载到客户端
List addressList = client.Web.Lists.GetByTitle("通讯录");
client.Load(addressList);
CamlQuery camlQueryForUser = new CamlQuery();
camlQueryForUser.ViewXml = @"<View/>";

ListItemCollection listItems = addressList.GetItems(camlQueryForUser);
client.Load(listItems);
client.ExecuteQuery();

foreach (ListItem item in listItems)
{
DataRow row = dt.NewRow();
row["ID"] = item["_x5de5__x53f7_"] == null ? "" : item["_x5de5__x53f7_"].ToString();
row["Name"] = item["_x59d3__x540d_"] == null ? "" : item["_x59d3__x540d_"].ToString();
row["Job"] = item["_x5c97__x4f4d_"] == null ? "" : item["_x5c97__x4f4d_"].ToString();
row["Department"] = item["_x90e8__x95e8_"] == null ? "" : item["_x90e8__x95e8_"].ToString();
row["Extension"] = item["_x5206__x673a_"] == null ? "" : item["_x5206__x673a_"].ToString();
row["Phone"] = item["_x76f4__x62e8__x7535__x8bdd_"] == null ? "" : item["_x76f4__x62e8__x7535__x8bdd_"].ToString();
row["MobilePhone"] = item["_x79fb__x52a8__x7535__x8bdd_"] == null ? "" : item["_x79fb__x52a8__x7535__x8bdd_"].ToString();
row["Email"] = item["_x7535__x5b50__x90ae__x4ef6_"] == null ? "" : item["_x7535__x5b50__x90ae__x4ef6_"].ToString();
row["Area"] = item["_x533a__x57df_"] == null ? "" : item["_x533a__x57df_"].ToString();
row["RoomNub"] = item["RoomNub"] == null ? "" : item["RoomNub"].ToString();
dt.Rows.Add(row);
}
}

#region 3、设置返回值

dt.AcceptChanges();
ds.Tables.Add(dt);

#endregion

return ds;
}

App_Code 中方法


using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using iWS.BPDI.MobilePortal.Common;
using log4net;
using iWS.BPDI.MobilePortal.IBLL;
using iWS.PublicUtilites;


/// <summary>
/// 企业门户统计信息管理相关
/// </summary>
[WebService(Namespace = "http://iws.mobileportal.ws/")]
public class PortalCenter : System.Web.Services.WebService
{
/// <summary>
/// 日志组件
/// </summary>
private static ILog log = LogManager.GetLogger(typeof(PortalCenter));

/// <summary>
/// 创建业务逻辑层处理对象
/// </summary>
private IPortalCenter iPortal = PortalCenterMaker.Create(Functions.GetAppSeetingValueByKey("BLLTarget"));

public PortalCenter()
{
//日志初始化
LogRecorder.InitLog();
}

[WebMethod]
public DataSet GetAddressList(string UserName, string UserPassword)
{
return iPortal.GetAddressList(UserName, UserPassword);
}
}

asmx中只有一句话即可

<%@ WebService Language="C#" CodeBehind="~/App_Code/PortalCenter.cs" class="PortalCenter" %>

WebService实则就这三层调用

posted @ 2012-08-16 14:14  717806198  阅读(327)  评论(0编辑  收藏  举报