SharePoint的WebService的应用
SharePoint自帶了WebService,通常情況下是跨服務(wù)器的訪問,因?yàn)橥环?wù)器上不同網(wǎng)站可以簡單的通過提升權(quán)限代碼就可以訪問數(shù)據(jù)。
以跨服務(wù)器讀取某個(gè)list為例,對(duì)項(xiàng)目添加“http://<server-url>/_vti_bin/Lists.asmx”和“http://<server-url>/_vti_bin/SiteData.asmx”的引用。
對(duì)兩個(gè)引用的命名分別為ListService和SiteDataService
//訪問列表庫,通過CAML查詢返回的是一個(gè)XML文件,不需要解析直接給DataSet類型賦值
?public static DataSet GetItems()
??????? {
??????????? ListService.Lists listsWS = new ListService.Lists();
??????????? //listsWS.Credentials = System.Net.CredentialCache.DefaultCredentials; //該句在編譯環(huán)境可以代替下一句,但是跨服務(wù)器應(yīng)用肯定要用下一句
??????????? 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;
??????? }
?以上代碼要特別注意兩點(diǎn):
1。身份驗(yàn)證。對(duì)web引用可以直接在webconfig里面直接修改地址,相應(yīng)的修改代碼中的驗(yàn)證登錄信息就可以,建議都弄到配置文件里,方便統(tǒng)一維護(hù)。
2。解析XML。
?
以下是引用的service對(duì)應(yīng)的映射列表
| 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 |
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/Hary/archive/2009/02/04/1383933.html
總結(jié)
以上是生活随笔為你收集整理的SharePoint的WebService的应用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 实用工具类库java.util
- 下一篇: .NET设计模式(15):结构型模式专题