首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 企业软件 > 行业软件 >

sharepoint2010 webservice 取得列表页面内容~解决思路

2012-03-22 
sharepoint2010 webservice 取得列表页面内容~急我想通过sharepoint2010 提供的webservice 远程访问,取得

sharepoint2010 webservice 取得列表页面内容~急
我想通过sharepoint2010 提供的webservice 远程访问,取得 指定列表下的所有页面的内容。比如说主页上发布了一条新闻,我需要取新闻的内容。如果某页面内容包含附件,也必须取得。
 请问各位高手,是否可行?能否提供思路。


[解决办法]
SharePoint自带了WebService,通常情况下是跨服务器的访问,因为同一服务器上不同网站可以简单的通过提升权限代码就可以访问数据。

以跨服务器读取某个list为例,对项目添加“http://<server-url>/_vti_bin/Lists.asmx”和“http://<server-url>/_vti_bin/SiteData.asmx”的引用。

对两个引用的命名分别为ListService和SiteDataService


//访问列表库,通过CAML查询返回的是一个XML文件,不需要解析直接给DataSet类型赋值


 public static DataSet GetItems()

{
ListService.Lists listsWS = new ListService.Lists();
//listsWS.Credentials = System.Net.CredentialCache.DefaultCredentials; //该句在编译环境可以代替下一句,但是跨服务器应用肯定要用下一句
listsWS.Credentials = new NetworkCredential(用户名, 密码, 域名);
XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml("<Document><Query><Where>CAML</Where></Query><ViewFields /><QueryOptions /></Document>");
XmlNode listQuery = doc.SelectSingleNode("//Query");
XmlNode listViewFields = doc.SelectSingleNode("//ViewFields");
XmlNode listQueryOptions = doc.SelectSingleNode("//QueryOptions");

Guid g = GetWebID();

XmlNode items = listsWS.GetListItems("ListName", string.Empty, listQuery, listViewFields, string.Empty, listQueryOptions, g.ToString());

NameTable nt = new System.Xml.NameTable();
XmlNamespaceManager nsMgr = new XmlNamespaceManager(nt);
nsMgr.AddNamespace("w", "http://schemas.microsoft.com/office/word/2003/2/wordml");
XmlNode y = items.SelectSingleNode("*", nsMgr);
DataSet ds = new DataSet();
if (y != null)
{
XmlReader xmlReader = new XmlTextReader(y.InnerXml, XmlNodeType.Element, null);
ds.ReadXml(xmlReader);
}
return ds;
}

private static Guid GetWebID()
{
SiteDataService.SiteData siteDataWS = new sinopecSiteData.SiteData();
siteDataWS.Credentials = new NetworkCredential(用户名, 密码, 域名);
SiteDataService._sWebMetadata webMetaData;
SiteDataService._sWebWithTime[] arrWebWithTime;
SiteDataService._sListWithTime[] arrListWithTime;
SiteDataService._sFPUrl[] arrUrls;
string roles; string[] roleUsers; string[] roleGroups;
uint i = siteDataWS.GetWeb(out webMetaData, out arrWebWithTime, out arrListWithTime, out arrUrls, out roles, out roleUsers, out roleGroups);
Guid g = new Guid(webMetaData.WebID);
return g;




 以上代码要特别注意两点:

1。身份验证。对web引用可以直接在webconfig里面直接修改地址,相应的修改代码中的验证登录信息就可以,建议都弄到配置文件里,方便统一维护。 


2。解析XML。

 

以下是引用的service对应的映射列表 


WSS Web Services Web Reference 
Administration Service http://<server-url:port-number>/_vti_adm/admin.asmx 
Alerts Service http://<server-url>/_vti_bin/alerts.asmx 
Document Workspace Service http://<server-url>/_vti_bin/dws.asmx 
Forms Service http://<server-url>/_vti_bin/forms.asmx 
Imaging Service http://<server-url>/_vti_bin/imaging.asmx 
List Data Retrieval Service http://<server-url>/_vti_bin/dspsts.asmx 
Lists Service http://<server-url>/_vti_bin/lists.asmx 
Meetings Service http://<server-url>/_vti_bin/meetings.asmx 
Permissions Service http://<server-url>/_vti_bin/permissions.asmx 
Site Data Service http://<server-url>/_vti_bin/sitedata.asmx 


Site Service http://<server-url>/_vti_bin/sites.asmx 
Users and Groups Service http://<server-url>/_vti_bin/usergroup.asmx 
Versions Service http://<server-url>/_vti_bin/versions.asmx 
Views Service http://<server-url>/_vti_bin/views.asmx 
Web Part Pages Service http://<server-url>/_vti_bin/webpartpages.asmx 
Webs Service http://<server-url>/_vti_bin/webs.asmx

[解决办法]
帮你顶起!
首先帮你回答一个问题:
1、返回的格式不是html代码,返回的是存在<_x2546_>节点的xml字符串,而<_x2546_>代表的是一个汉字,节点内的值就是存放咋列表中某个字段的值。
2、至于附件我就不清楚webservice返回的形式是什么样的,我猜测应该是二进制吧(没有证实,慎重)。

SharePoint2010新特性: 客户端对象模型
使用客户端对象模型,可以像在服务器端使用对象操作列表,何不试试,方便,而且性能应该不次于webservice。
参考:http://www.cnblogs.com/ww3128/archive/2010/12/05/1897045.html
[解决办法]
mark
[解决办法]
1、如果你确实是以Web引用的方式引用的 /_vti_bin/lists.asmx 的话,应该就会有Lists类(这个Lists不是属性,这里面的ListService是你在引用Web Service的时候输入的命名空间,Lists是其中的一个类)
2、SharePoint并不会因为是试用版接口就有所不同
3、如果是2010,你可以使用客户端对象模型(具体请查看SDK,或者google “SharePoint 2010 Client Object Model”),这个的能力要比Web Service强很多,而且不用直接和那些xml打交道

热点排行