SharePoint Web Service的身份验证
2009-09-01 11:59
399 查看
SharePoint内置了一套相对比较完整的Web Services提供给开发者,这样就可以在客户端、跨平台的程序中读取甚至修改SharePoint中的内容。不过当SharePoint网站不允许匿名访问的时候,调用Web Services自然也需要提供身份验证。
SharePoint身份验证最常用的是Windows验证(Windows Authentication)和表单验证(Form Authentication)两种。
Windows验证即使用Windows账号或者AD账号来进行身份验证,对于这种验证方式,在SharePoint SDK中已经给出了如何提供身份验证的方法.
假设我们使用最常用的lists.asmx来获取SharePoint列表数据,添加的Web引用的命名空间是 spwsList.
使用当前帐户身份:
使用指定帐户:
表单认证是SharePoint 2007新加入的一种身份认证方式,其后台是使用.Net Framework中的Membership机制进行用户身份的识别,对于外网来说,大都是使用表单认证的方式来实现的。在使用表单认证的SharePoint网站中通过Web Service获取数据稍微麻烦一些,不过也可以通过SharePoint提供的表单认证Web Service来创建用户身份相关的Cookie。
表单认证Web Service的地址是:http://[server]/[site]/_vti_bin/authentication.asmx
在使用Web Service的程序中再次加入上面这个Web引用,假设其命名空间是spwsAuth,那么使用表单认证构造身份并访问数据的代码实例如下:
文章来源:>>http://blog.joycode.com/erucy/archive/2008/07/28/115205.aspx
SharePoint身份验证最常用的是Windows验证(Windows Authentication)和表单验证(Form Authentication)两种。
Windows验证即使用Windows账号或者AD账号来进行身份验证,对于这种验证方式,在SharePoint SDK中已经给出了如何提供身份验证的方法.
假设我们使用最常用的lists.asmx来获取SharePoint列表数据,添加的Web引用的命名空间是 spwsList.
使用当前帐户身份:
spwsList.Lists wsLists = new spwsList.Lists(); wsLists.Credentials = CredentialCache.DefaultCredential; Console.WriteLine(wsLists.GetListCollection().OuterXml);
使用指定帐户:
spwsList.Lists wsLists = new spwsList.Lists(); wsLists.Credentials = new NetworkCredential("username", "password", "domain"); Console.WriteLine(wsLists.GetListCollection().OuterXml)上面的CredentialCache、NetworkCredential都是在System.Net命名空间下。
表单认证是SharePoint 2007新加入的一种身份认证方式,其后台是使用.Net Framework中的Membership机制进行用户身份的识别,对于外网来说,大都是使用表单认证的方式来实现的。在使用表单认证的SharePoint网站中通过Web Service获取数据稍微麻烦一些,不过也可以通过SharePoint提供的表单认证Web Service来创建用户身份相关的Cookie。
表单认证Web Service的地址是:http://[server]/[site]/_vti_bin/authentication.asmx
在使用Web Service的程序中再次加入上面这个Web引用,假设其命名空间是spwsAuth,那么使用表单认证构造身份并访问数据的代码实例如下:
spwsAuth.Authentication auth = new spwsAuth.Authentication(); auth.CookieContainer = new CookieContainer(); auth.AllowAutoRedirect = true; spwsAuth.LoginResult lr = auth.Login("username", "password"); if (lr.ErrorCode == spwsAuth.LoginErrorCode.NoError) { spwsList.Lists wsList = new spwsList.Lists(); wsList.CookieContainer = auth.CookieContainer; XmlNode res = wsList.GetListCollection(); Console.WriteLine(res.OuterXml); }
文章来源:>>http://blog.joycode.com/erucy/archive/2008/07/28/115205.aspx
相关文章推荐
- SharePoint Web Service的身份验证
- SharePoint Web Service的身份验证
- SharePoint Web Service的身份验证
- SharePoint Web Service的身份验证
- SharePoint WebService 之更新审批状态
- SharePoint Web Service系列:获取文档的属性信息
- java调用sharepoint webservice
- 关于WEB Service&WCF&WebApi实现身份验证之WebApi篇
- SharePoint WebService——根据群组名称获取成员信息
- cxf webservice身份验证
- 分别用(Windows/Form/Soap/WebService)实现用户身份验证(含示例代码下载)
- SharePoint Web Service系列:编写自定义SharePoint Web Services之二
- Flash + SharePoint WebService播放视频 (一)
- SharePoint Web Service系列:编写自定义SharePoint Web Services之二
- C# Web Service非Soap头(Session)身份验证方法
- SharePoint Web Service系列:编写自定义SharePoint Web Services
- SharePoint Authentication WebService的Login方法缺陷
- SharePoint Web Service系列:进行列表的增删改
- SharePoint WebService——根据群组名称获取成员信息
- 工具:sharepoint webservice:根据asmx生成disco和wsdl文件