在 Infopath 2007 中访问 SharePoint 用户配置文件服务






3.33/5 (2投票s)
2007年4月26日

32620
在 Infopath 2007 中访问用户配置文件服务。
引言
本文档介绍了如何在 Infopath 表单中访问 SharePoint 用户配置文件服务,并解释了配置设置。
使用代码
此代码假定 SharePoint (MOSS) 服务器包含 EmployeeId 和 Preferred Name 属性。
首先,添加一个 Web 引用 (http://MOSSSERVERNAME/_vti_bin/userprofileservice.asmx)。我将 Web 引用命名为 localhost。您可以根据需要使用不同的名称,然后您需要更改代码。
private string GetUserProfileByEmployeeId(string EmpId)
{
string displayName = string.Empty;
localhost.UserProfileService myUPWS = new localhost.UserProfileService();
myUPWS.Credentials = System.Net.CredentialCache.DefaultCredentials;
long profileCount = myUPWS.GetUserProfileCount();
localhost.GetUserProfileByIndexResult up;
localhost.PropertyData[] propdata;
for (int j = 0; j < profileCount; j++)
{
up = myUPWS.GetUserProfileByIndex(j);
propdata = up.UserProfile;
if (propdata[propdata.Length - 1].Values.Length > 0)
{
if (propdata[propdata.Length - 1].Values[0].Value.ToString()
== EmpId)
{
displayName = propdata[4].Values[0].Value.ToString();
break;
}
}
}
return displayName;
}
因此,上面的代码在您将 EmployeeId
传递给用户配置文件服务时会返回 Preferred Name。由于我们在 Infopath 表单中使用 Web 服务,因此必须将安全级别更改为“完全信任”。此外,如果表单要从开发机器或 MOSS 服务器机器以外的其他机器访问,则必须对表单进行签名。
此外,我们必须配置 MOSS 服务器的 IIS,以便 Infopath 表单可以从其他机器访问用户配置文件服务。
- 转到 IIS 并查找 UserProfileServices.asmx 文件,然后单击“属性”。
- 单击“安全通信”部分中的“编辑”。
- 现在选择“接受客户端证书”并单击“确定”。
这将使 Infopath 表单能够从其他机器访问用户配置文件服务。