SharePoint如何調用WebService操作List

來源:互聯網
上載者:User

在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資訊結果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.