2014-10-30 53 views
0

我有一個在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); 

這總是返回一個空的結果。我如何首先檢索與電話號碼關聯的用戶以獲取其電話號碼?

+0

當您說'來自外部來源的呼叫'時,此外部來源是聯合網絡嗎?如果外部來源只是一個電話而不是一個lync/skype/etc客戶端,那麼它不會有任何出現。 – 2014-11-06 07:24:25

+0

我的意思是來自網絡外的電話或手機的呼叫。我已經自己找到了一個「解決方案」,但我希望有一個更好的解決方案。 – Kirschi 2014-11-06 07:34:57

回答

0

我解決這樣說:

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是否等於用戶的電子郵件或電話。

0

我發現了其他兩種方法來解決您的問題。

在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的吧!

相關問題