从UCMA应用程序中的电话号码检索Lync联系人
问题描述:
我有一个在Lync 2013服务器上运行并使用MSPL的C#托管应用程序。我将每个来自MSPL的呼叫路由到应用程序并在那里处理。 Lync到Lync的调用工作正常,它们的to
标题的格式为sip:[email protected]
。但是,当从网络外部(非手机等lync)向Lyncuser的工作电话发起呼叫时,Uri就像sip:[email protected];user=phone
(sip:[workphone] @domain)。将此字符串传递给Presence Retrieval功能不起作用。从UCMA应用程序中的电话号码检索Lync联系人
var sips = new string[] { phone }; // The "To" number
presenceService.BeginPresenceQuery(sips, categories, null, null, null);
这总是返回一个空的结果。我如何首先检索与电话号码关联的用户以获取其电话号码?
答
我解决这样说:
public static UserObject FindContactBySip(string sip)
{
return UserList.FirstOrDefault(u => u.HasSip(sip));
}
private static void InitFindUsersInAD()
{
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
var user = new UserPrincipal(ctx);
user.Name = "*";
var searcher = new PrincipalSearcher(user);
var result = searcher.FindAll();
var sipList = new List<string>();
UserList = new List<UserObject>();
foreach (var res in result)
{
var underlying = (DirectoryEntry)res.GetUnderlyingObject();
string email = string.Empty, phone = string.Empty, policies = string.Empty;
foreach (var keyval in underlying.Properties.Values)
{
var kv = keyval as System.DirectoryServices.PropertyValueCollection;
if (kv != null && kv.Value is string)
{
if (kv.PropertyName.Equals("msRTCSIP-PrimaryUserAddress"))
{
email = (kv.Value ?? string.Empty).ToString();
}
else if (kv.PropertyName.Equals("msRTCSIP-Line"))
{
phone = (kv.Value ?? string.Empty).ToString();
}
else if (kv.PropertyName.Equals("msRTCSIP-UserPolicies"))
{
policies = (kv.Value ?? string.Empty).ToString();
}
}
}
if (!string.IsNullOrEmpty(phone) && !string.IsNullOrEmpty(email))
{
var userobj = new UserObject(email, phone, policies);
UserList.Add(userobj);
}
}
}
首先我初始化UserList
(名单//自定义类),从AD。然后我拨打FindContactBySip
并检查提供的SIP是否等于用户的电子邮件或电话。
答
我发现了其他两种方法来解决您的问题。
在MSPL您可以:
toContactCardInfo = QueryCategory(toUserUri, 0, "contactCard", 0);
它给你:
<contactCard xmlns=""http://schemas.microsoft.com/2006/09/sip/contactcard"" >
<identity >
<name >
<displayName >
Lync User</displayName>
</name>
<email >
[email protected]</email>
</identity>
</contactCard>
您可以打开电子邮件地址转换成SIP地址。这只适用于您的lync设置使用电子邮件地址作为SIP地址。
另一种方法是使用'P-Asserted-Identity'SIP标头来确定电话呼叫路由到谁。唯一的问题是,它并没有出现在初始邀请中(就像无论如何对于From一样),但是在来自Lync Client的180响铃响应中。
P-Asserted-Identity: <sip:[email protected]>, <tel:+123456789;ext=12345>
因此,如果你等待180振铃响应,那么我会推荐你使用P-宣称身份法,你甚至都不需要逃出MSPL的吧!
当您说'来自外部来源的呼叫'时,此外部来源是联合网络吗?如果外部来源只是一个电话而不是一个lync/skype/etc客户端,那么它不会有任何出现。 – 2014-11-06 07:24:25
我的意思是来自网络外的电话或手机的呼叫。我已经自己找到了一个“解决方案”,但我希望有一个更好的解决方案。 – Kirschi 2014-11-06 07:34:57