当前位置:编程学习 > asp >>

步步为营 SharePoint 开发学习笔记系列 九、SharePoint web service 开发(上)

 

概要

 

    Sharepoint中提供了很多开箱即用的Web Service,使用这些web service我们可以进行远程调用, 在"web server extensions\12\ISAPI"(其通常位于C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI")之下的"Microsoft Shared"目录中有大部分Web Services的物理文件。用于管理中心工具的管理Web Service位于ADMISAPI文件夹中,其在管理中心控制台里是一个名为"_vti_adm"的虚拟目录。当你创建了一个SharePoint站点时,它将包含一个名为"_vti_bin"的虚拟目录,以指向这个位置。IIS不为子站点包含任何应用程序或虚拟目录,它们只是包含通过SharePoint元数据和HttpModules实现的对_vti_bin虚拟目录的映射。

 

先看下Lists.asmx中的一些常用功能

1

 

 

首先我们先连接web Service

 

view sourceprint?01 public static NetworkCredential GetCredentials(SiteType type) 

 

02 { 

 

03  

 

04         return new System.Net.NetworkCredential(ConfigurationManager.AppSettings["Source_SPWSUserName"], 

 

05             ConfigurationManager.AppSettings["Source_SPWSUserPassword"], ConfigurationManager.AppSettings["Source_SPWSDomain"]); 

 

06 } 

 

07  

 

08 /// <summary> 

 

09 /// Get the list webservice based on the url 

 

10 /// </summary> 

 

11 /// <returns></returns> 

 

12 public static SPListWS.Lists GetListWebService(ListBE listProperty) 

 

13 { 

 

14     string wsUrl = GetWSUrl(listProperty) + "_vti_bin/Lists.asmx"; 

 

15     SPListWS.Lists ws = new SPListWS.Lists(); 

 

16     ws.Url = wsUrl; 

 

17     ws.Credentials = WSHelper.GetCredentials(listProperty.Type); 

 

18  

 

19     return ws; 

 

20 }

 

再把web service引用进来

image

 

 

Lists.GetListItems的用法

 

根据条件来查询的query语句

 

view sourceprint?01 private string GetCondition 

 

02 { 

 

03     get

 

04     { 

 

05         return @"<Where> 

 

06                   <And> 

 

07                      <And> 

 

08                         <Geq> 

 

09                            <FieldRef Name='Created' /> 

 

10                            <Value Type='DateTime'>{0}</Value>  

 

11                         </Geq> 

 

12                         <Leq> 

 

13                            <FieldRef Name='Created' /> 

 

14                            <Value Type='DateTime'>{1}</Value> 

 

15                         </Leq> 

 

16                      </And> 

 

17                      <Gt> 

 

18                         <FieldRef Name='ID' /> 

 

19                         <Value Type='Counter'>0</Value> 

 

20                      </Gt> 

 

21                   </And> 

 

22             </Where>"; 

 

23     } 

 

24 }

 

而后再调用Lists.GetListItems方法,返回的是XmlNode的结果集

 

view sourceprint?01 /// <summary> 

 

02 ///  

 

03 /// </summary> 

 

04 /// <returns></returns> 

 

05 private List<ListItemBE> GetSourceListItems(DateTime startDate, DateTime endDate) 

 

06 { 

 

07     int rowLimit = 8000; 

 

08     XmlDocument xmlDoc = new System.Xml.XmlDocument(); 

 

09     XmlElement query = xmlDoc.CreateElement("Query"); 

 

10     XmlElement viewFields = xmlDoc.CreateElement("ViewFields"); 

 

11  &nbs

补充:Web开发 , ASP.Net ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,