使用Unified Communications Managed API获取Lync在线会议的链接地址

在企业内部使用Outlook和Lync的读者一定知道,Outlook中有一个Lync的插件,当启用了该插件后,即可在“日历”视图中通过单击New Lync Meeting按钮来安排一个带有Lync在线会议链接地址的Appointment:

8-9-2013 4-51-42 PM

正如上图所示,在这个Appointment窗口中,有个Join Lync Meeting的超级链接,鼠标移动到这个链接上,会提示出其所对应的超级链接地址,也就是Lync在线会议的链接地址。现在,我们就需要通过编写C#程序的方式,来获得这个Lync在线会议的链接地址。

SDK的选择

经过上网搜索研究,与Outlook和Lync相关的SDK大致有以下几种:

  1. Lync 2010/2013 SDK
  2. Exchange Web Services (EWS)
  3. Unified Communications Managed API (UCMA)
  4. Unified Communications Web API (UCWA)

Lync 2010/2013 SDK主要是通过Automation对象来实现Lync客户端的操作,因此,使用Lync SDK时,Lync客户端需要一直运行,否则无法获得Automation对象。Lync SDK也支持Suppress UI的模式,这样开发者就可以屏蔽Lync的用户界面,而使用自己的软件界面来使用Lync客户端的功能,但无论是否是Suppress UI的模式,都需要Lync客户端一直运行。

Exchange Web Services (EWS)是一套访问Exchange Server的API,通过使用EWS,可以在程序中通过Exchange Server发送电子邮件、管理电子邮件、安排Outlook会议,以及管理自己的Outlook文件夹等等。

Unified Communications Managed API (UCMA) 是一套基于.NET的API,通过使用UCWA,可以获得Microsoft Lync Server的增强状态信息、即时消息、电话、视频、音频、会议等的访问和控制功能。

Unified Communications Web API (UCWA) 是UCMA的Web版,通过Javascript、Json等技术向异构平台提供UCMA的功能。

终上所述,在我们的应用中,应该选择Unified Communications Managed API (UCMA)来实现Lync在线会议链接地址的获取。

代码实现

首先需要安装Unified Communications Web API,这可以到微软的官方网站下载。下载安装之后,即可开始编写代码。

创建一个控制台应用程序(Console Application),添加对Microsoft.Rtc.Collaboration.dll程序集的引用。之后,还需要会议组织者在企业中的电子邮件地址,以及Lync服务器的地址。前者容易获得,读者可以使用自己的邮件地址进行测试;而Lync服务器的地址,则可以在托盘中右键单击Lync图标,在弹出的菜单中选择显示Lync详细信息的选项来获得。

下面的代码完整地展示了通过UCMA来获取Lync在线会议的链接地址,具体内容请参考代码中的注释:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using  System;
using  System.Threading;
using  Microsoft.Rtc.Collaboration;
using  Microsoft.Rtc.Collaboration.ConferenceManagement;
using  Microsoft.Rtc.Signaling;
 
namespace  ConsoleApplication7
{
     class  Program
     {
         static  AutoResetEvent platformStartupCompleted = new  AutoResetEvent( false );
         static  AutoResetEvent endpointInitCompleted = new  AutoResetEvent( false );
         static  AutoResetEvent conferenceScheduleCompleted = new  AutoResetEvent( false );
 
         static  void  Main( string [] args)
         {
             var  ownerURI = "<在此填写会议组织者URI,格式为:sip:邮箱地址>" ;
             var  serverAddress = "<在此填写Lync服务器地址>" ;
             var  applicationName = "ConsoleApplication" ;
             // 通过ClientPlatformSettings来初始化一个CollaborationPlatform。
             // 注意,Transport Type应使用SipTransportType.Tls。
             ClientPlatformSettings clientPlatformSettings = new  ClientPlatformSettings(applicationName,
                 SipTransportType.Tls);
             CollaborationPlatform platform = new  CollaborationPlatform(clientPlatformSettings);
             // 启动CollaborationPlatform实例
             platform.BeginStartup(platformEndStartup, platform);
             platformStartupCompleted.WaitOne();
             Console.WriteLine( "Platform initialized..." );
 
             // 通过UserEndpointSettings来初始化一个UserEndpoint。
             UserEndpointSettings userEndpointSettings = new  UserEndpointSettings(ownerURI, serverAddress);
             userEndpointSettings.Credential = System.Net.CredentialCache.DefaultNetworkCredentials;
             UserEndpoint endpoint = new  UserEndpoint(platform, userEndpointSettings);
             // 建立UserEndpoint的连接
             endpoint.BeginEstablish(endpointEndEstablish, endpoint);
             endpointInitCompleted.WaitOne();
             Console.WriteLine( "Endpoint initialized..." );
 
             // 设置会议的创建选项,详细的设置选项请参考ConferenceScheduleInformation类的定义。
             ConferenceScheduleInformation conferenceScheduleInformation = new  ConferenceScheduleInformation();
             conferenceScheduleInformation.AccessLevel = ConferenceAccessLevel.Invited;
             conferenceScheduleInformation.Description = "Conference Description" ;
             ConferenceParticipantInformation participantA_Information =
                 new  ConferenceParticipantInformation(ownerURI, ConferencingRole.Leader);
             conferenceScheduleInformation.Participants.Add(participantA_Information);
             conferenceScheduleInformation.LobbyBypass = LobbyBypass.EnabledForGatewayParticipants;
             conferenceScheduleInformation.AutomaticLeaderAssignment = AutomaticLeaderAssignment.SameEnterprise;
             ConferenceMcuInformation audioVideoMCU = new  ConferenceMcuInformation(McuType.AudioVideo);
             conferenceScheduleInformation.Mcus.Add(audioVideoMCU);
 
             // 根据会议的创建选项创建新的Lync会议
             endpoint.ConferenceServices.BeginScheduleConference(conferenceScheduleInformation,
                 conferenceEndScheduled, endpoint.ConferenceServices);
             
             conferenceScheduleCompleted.WaitOne();
 
             Console.WriteLine( "Press anykey to exit." );
             Console.ReadLine();
         }
 
         static  void  conferenceEndScheduled(IAsyncResult ar)
         {
             try
             {
                 ConferenceServices session = (ConferenceServices)ar.AsyncState;
                 Conference conference = session.EndScheduleConference(ar);
                 // 在控制台输出Lync会议的链接地址
                 Console.WriteLine(conference.WebUrl);
             }
             catch
             {
                 throw ;
             }
             finally
             {
                 conferenceScheduleCompleted.Set();
             }
         }
 
         static  void  endpointEndEstablish(IAsyncResult ar)
         {
             try
             {
                 UserEndpoint endpoint = ar.AsyncState as  UserEndpoint;
                 endpoint.EndEstablish(ar);
             }
             catch
             {
                 throw ;
             }
             finally
             {
                 endpointInitCompleted.Set();
             }
         }
 
         static  void  platformEndStartup(IAsyncResult ar)
         {
             try
             {
                 CollaborationPlatform collabPlatform = ar.AsyncState as  CollaborationPlatform;
                 collabPlatform.EndStartup(ar);
             }
             catch
             {
                 throw ;
             }
             finally
             {
                 platformStartupCompleted.Set();
             }
         }
     }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值