我有一个服务器应用程序 - 在极少数情况下发生意外错误 - 应向Lync用户(终端)发送即时消息。哪个Lync SDK?从托管代码发送即时消息
从我读到的内容来看,我无法使用Lync Client SDK,因为它依赖于应用程序服务器上正在运行的Lync客户端。然而这是不可能的。 UCWA似乎是一个公平的选择,但我并不想真正开始编写自己的Lync API,将所有HttpClient聊天记录隐藏在托管代码封装中。
这个简单用例的最佳选择是什么?
我有一个服务器应用程序 - 在极少数情况下发生意外错误 - 应向Lync用户(终端)发送即时消息。哪个Lync SDK?从托管代码发送即时消息
从我读到的内容来看,我无法使用Lync Client SDK,因为它依赖于应用程序服务器上正在运行的Lync客户端。然而这是不可能的。 UCWA似乎是一个公平的选择,但我并不想真正开始编写自己的Lync API,将所有HttpClient聊天记录隐藏在托管代码封装中。
这个简单用例的最佳选择是什么?
我会推荐使用UCMA - 统一通信托管API。如果是发送的一次性即时消息,并且您不需要扩展以处理多个同时会话等的应用程序,则可以使用UserEndpoint,因为它比ApplicationEndpoint的工作和设置少一点。
我有一个在我的博客上这样做的工作示例:http://thoughtstuff.co.uk/2013/03/creating-ucma-applications-with-a-userapplication-instance-example-sending-ims/其中还有一些关于您拥有的不同选项的更多信息。
然而,对于完整性(!因为这么会比我的博客很长时间了我期望的那样)下面的代码:
using Microsoft.Rtc.Collaboration;
using System;
namespace SimpleUserUCMA
{
class Program
{
private const string sipaddress = "sip:[email protected]";
private const string username = "USERNAME";
private const string password = "PASSWORD";
private const string domain = "DOMAIN";
private const string destinationSip = "sip:[email protected]";
private const string IMMessage = "Hello!";
static CollaborationPlatform _collabPlatform { get; set; }
static UserEndpoint _endpoint { get; set; }
static bool _OKToQuit = false;
static void Main(string[] args)
{
string userAgent = "ClientPlatformExample";
var platformSettings = new ClientPlatformSettings(userAgent, Microsoft.Rtc.Signaling.SipTransportType.Tls);
_collabPlatform = new CollaborationPlatform(platformSettings);
//Start up the platform, calling back asynchronously once it's done.
_collabPlatform.BeginStartup(EndCollabPlatformStartup, null);
//In this example, wait for everything to finish before exiting
while (!_OKToQuit)
{
System.Threading.Thread.Sleep(2000);
}
}
private static void EndCollabPlatformStartup(IAsyncResult ar)
{
_collabPlatform.EndStartup(ar);
//A collaboration plaform can have one or more Endpoints. An Endpoint is tied to a SIP Address.
UserEndpointSettings settings = new UserEndpointSettings(sipaddress);
settings.Credential = new System.Net.NetworkCredential(username, password, domain);
settings.AutomaticPresencePublicationEnabled = true;
_endpoint = new UserEndpoint(_collabPlatform, settings);
_endpoint.BeginEstablish(UserEndpointEstablishCompleted, null);
}
private static void UserEndpointEstablishCompleted(IAsyncResult ar)
{
_endpoint.EndEstablish(ar);
//Once the endpoint is in place, create a Conversation and an IM Call.
var Conversation = new Conversation(_endpoint);
var Call = new InstantMessagingCall(Conversation);
//When the call is established, Flow will be created. Flow is how you sent IMs around. Therefore, just before
//establishing, we attach an event handler to catch the flow being setup (it's state will change to Active)
Call.InstantMessagingFlowConfigurationRequested += Call_InstantMessagingFlowConfigurationRequested;
Call.BeginEstablish(destinationSip, new CallEstablishOptions(), EndBeginEstablish, Call);
}
private static void EndBeginEstablish(IAsyncResult ar)
{
Call call = (Call)ar.AsyncState;
call.EndEstablish(ar);
}
static void Call_InstantMessagingFlowConfigurationRequested(object sender, InstantMessagingFlowConfigurationRequestedEventArgs e)
{
//Once we're notified about this, we get a handle to the newly created Flow. Let's use this to register for state changes.
e.Flow.StateChanged += Flow_StateChanged;
}
static void Flow_StateChanged(object sender, MediaFlowStateChangedEventArgs e)
{
if (e.State == MediaFlowState.Active)
{
//The flow is now active! We can use it to send messages.
InstantMessagingFlow flow = (InstantMessagingFlow)sender;
flow.BeginSendInstantMessage(IMMessage, EndBeginSendInstanceMessage, flow);
}
}
private static void EndBeginSendInstanceMessage(IAsyncResult ar)
{
InstantMessagingFlow flow = (InstantMessagingFlow)ar.AsyncState;
flow.EndSendInstantMessage(ar);
//Having sent the message, terminate the conversation
flow.Call.Conversation.BeginTerminate(EndBeginTerminate, flow.Call.Conversation);
}
private static void EndBeginTerminate(IAsyncResult ar)
{
Conversation conversation = (Conversation)ar.AsyncState;
conversation.EndTerminate(ar);
_OKToQuit = true;
}
}
}
非常好。它的工作:)现在我只需要弄清楚如何直接发送消息,而不是“邀请某人进行对话”。谢谢! – lapsus 2013-05-10 14:26:48
不错,我很高兴。请你能将它标记为选定的答案吗?谢谢! – 2013-05-16 10:31:16
还挺新的:)所以我实际上想把这个标记为答案,但据我所知,它的评分为+1。无论如何,我现在标记为答案。您是否知道如何直接向终端发送消息 - 没有事先邀请? – lapsus 2013-05-17 08:47:13