当我查询我的Web服务以查找用户时,如果该用户不是该站点的SharePoint组的一部分,则该ID为-1。
但是,用户可以通过组权限进入该站点。因此,我的Web服务调用无法将用户添加到列表中的“人员”框中,即使SharePoint本身可以添加它。
我的Web服务调用如下:
String searchText = "[My User's Login Name, Spelled Exactly as it appears in SharePoint.]";
String maxresults = "100";
String pType = "All";
String body = "<?xml version=\"1.0\"?>"
+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
+ " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
+ " xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ "<soap:Body>"
+ " <SearchPrincipals "
+ " xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">"
+ " <searchText>" + searchText + "</searchText>"
+ " <maxResults>" + maxResults + "</maxResults>"
+ " <principalType>" + pType + "</principalType>"
+ " </SearchPrincipals>"
+ " </soap:Body>"
+ "</soap:Envelope>";
我从网络服务电话获得以下回复:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<SearchPrincipalsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<SearchPrincipalsResult>
<PrincipalInfo>
<AccountName>[User's Account Name]</AccountName>
<UserInfoID>-1</UserInfoID> <------------ NOTE THE -1 HERE -----------------
<DisplayName>[User's full name, exactly as I sent it in]</DisplayName>
<Email>...</Email>
<Department>...</Department>
<Title>...</Title>
<IsResolved>true</IsResolved>
<PrincipalType>User</PrincipalType>
</PrincipalInfo>
</SearchPrincipalsResult>
</SearchPrincipalsResponse>
</soap:Body>
</soap:Envelope>
如果我使用此信息将用户添加到“人员”框中,则通过Web服务,该条目变为“-1; #My User Name”,当然它无法找到,因此List.asmx webservice返回0x81020054 : The user does not exist or is not unique.
当我将用户直接添加到网站中的某个群组时,他们的ID就会解决得很好,所有内容都会正常进行。我从组中删除它们并再次返回-1。
有关始终返回有效身份证件的任何想法和/或建议?
答案 0 :(得分:1)
我可以看到你正在使用SearchPrincipals方法。而是尝试使用ResolvePrincipals方法。
此处的文档:http://msdn.microsoft.com/en-us/library/people.people.resolveprincipals(v=office.12).aspx
该方法有一个bool参数,你可以指定如果用户不属于该网站,那么应该添加它,这样你总是会确保你总是得到ID,即使用户没有属于该网站。
PeopleWebService.People pe = new PeopleWebService.People(); //People.asmx web service
string[] users = new string[] { "youruser" };
PeopleWebService.PrincipalInfo[] pInfo = pe.ResolvePrincipals(users, PeopleWebService.SPPrincipalType.User, true); //third param is true
string userID = pInfo[0].UserInfoID.ToString();