Sharepoint模拟外部web服务调用
本文关键字:服务 调用 web 外部 模拟 Sharepoint | 更新日期: 2023-09-27 18:15:52
我创建了一个运行在不同机器/IIS上的web服务,而不是我的SharePoint(2013)应用程序节点(双跳问题开始出现)。我将这个web服务公开给我们公司的其他服务。
下面的代码片段将成功检索使用专用凭据的SharePoint列表。"sp_admin_user")。
在我的web服务中,我可以检索调用它的用户的用户名(w/o密码ofc),这也存在于SharePoint中。
我的问题:我需要如何改变下面的代码,以方便与上述用户名模拟?
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string get_sp_list()
{
SPLists.Lists myservice = new SPLists.Lists();
myservice.Credentials = new System.Net.NetworkCredential( "sp_admin_user", "password123", "domain" );
myservice.Url = "https://sharepoint.company.com/sites/testground/_vti_bin/Lists.asmx";
[.. setting of variables ..]
System.Xml.XmlNode n = myservice.GetListItems(
sidList,
sidView,
query,
viewFields,
rowLimit,
queryOptions,
null
);
[.. compose json ..]
return json;
}
唯一可以在没有密码的情况下模拟的用户是SharePoint IIS应用程序池用户(通常是NETWORK SERVICE)。要模拟访问SharePoint页面的用户,运行SharePoint的计算机需要具有对外部服务的委托权限。你可以在这里读到。这都是关于安全限制的。
我建议你拒绝模拟方法,它更容易处理密码,使匿名web服务调用或发明其他东西。
您可以像这样模拟用户:
using (var ctx = WindowsIdentity.Impersonate(IntPtr.Zero))
{
//external web service call as "COMPUTER_NAME'NETWORK_SERVICE" user
}
如果您有密码,您也可以获得真正的用户令牌(而不是IntPtr.Zero)。