在SharePoint的使用中,经常需要进行系统集成这样的操作,我们作为SharePoint开发,就需要给其他系统提供接口,而SharePoint提供的WebService就很好的提供了这样的功能,我们简单了解下,通过SharePoint提供WebService对列表进行操作
步骤:
1、 首先,新建一个控制台程序,添加WebService的引用
地址http://<site>/_vti_bin/Lists.asmx
<site>为网站的地址,包括端口号
2、引用 - 右键 - 添加服务引用(如图1)– 高级 – 添加Web引用 – URL处填写WebService地址(如图2)
(图1)
(图2)
3、 获取List信息
try
{
WebServices1.Lists listService = new GetListTest.WebServices1.Lists();
listService.Credentials = System.Net.CredentialCache.DefaultCredentials;
XmlNode ndLists = listService.GetList("Test");//参数列表名,String类型
Console.Write(ndLists.OuterXml);
}
catch (Exception ex)
{
Console.Write(ex.Message);
}
4、 获取List信息结果
5、 获取ListItem信息
//获取ListItem信息
WebServices1.Lists listService = new GetListTest.WebServices1.Lists();
listService.Credentials = System.Net.CredentialCache.DefaultCredentials;
XmlDocument xmlDoc = new System.Xml.XmlDocument();
XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "");
XmlNode ndQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "");
ndQueryOptions.InnerXml = ""; //Query设置
ndViewFields.InnerXml = ""; //视图设置
ndQuery.InnerXml = ""; //Caml语句
try
{
XmlNode ndListItems = listService.GetListItems("Test", null, ndQuery, ndViewFields, "1", ndQueryOptions, null); //获取列表内容
Console.Write(ndListItems.OuterXml); //输出获取的Xml内容
}
catch (System.Web.Services.Protocols.SoapException ex)
{
}
查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/web/sharepoint/
6、 获取ListItem信息结果