Guest User

Untitled

a guest
Nov 10th, 2017
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.63 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3. using Microsoft.Rtc.Collaboration;
  4.  
  5. namespace SimpleUserUCMA
  6. {
  7. class Program
  8. {
  9. private const string sipaddress = "sip:example@domain.com";
  10. private const string username = "example@domain.com";
  11. private const string password = "password@1234";
  12. private const string domain = "domain.com";
  13. private const string destinationSip = "liveagent1@ngwplab.com";//serveraddress@domain.com
  14. private const string IMMessage = "Hello";
  15.  
  16.  
  17. static CollaborationPlatform _collabPlatform { get; set; }
  18. static UserEndpoint _endpoint { get; set; }
  19. static bool _OKToQuit = false;
  20. private static InstantMessagingCall call;
  21. private static InstantMessagingFlow flow;
  22. private static string incomingMessage;
  23. private static ManualResetEvent incomingMessageWaiter = new ManualResetEvent(false);
  24. private static ManualResetEvent flowWaiter = new ManualResetEvent(false);
  25. static void Main(string[] args)
  26. {
  27. string userAgent = "Mozilla/5.0 (X11; CrOS x86_64 8172.45.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.64 Safari/537.36";
  28.  
  29. var platformSettings = new ClientPlatformSettings(userAgent, Microsoft.Rtc.Signaling.SipTransportType.Tls);
  30. _collabPlatform = new CollaborationPlatform(platformSettings);
  31.  
  32. //Start up the platform, calling back asynchronously once it's done.
  33. _collabPlatform.BeginStartup(EndCollabPlatformStartup, null);
  34.  
  35. // Wait for a message to arrive and the flow to be ready.
  36. incomingMessageWaiter.WaitOne();
  37. flowWaiter.WaitOne();
  38.  
  39. // Process the incoming message. For this example just echo what was received.
  40. var reply = "You send me: " + incomingMessage;
  41.  
  42. // And reply to the sender.
  43. SendReplyMessage(reply);
  44. //In this example, wait for everything to finish before exiting
  45. while (!_OKToQuit)
  46. {
  47. Thread.Sleep(2000);
  48. }
  49. }
  50. private static void EndCollabPlatformStartup(IAsyncResult ar)
  51. {
  52. _collabPlatform.EndStartup(ar);
  53. //A collaboration plaform can have one or more Endpoints. An Endpoint is tied to a SIP Address.
  54. UserEndpointSettings settings = new UserEndpointSettings(sipaddress,"00.000.63.216",5061);
  55. settings.Credential = new System.Net.NetworkCredential(username, password, domain);
  56. settings.AutomaticPresencePublicationEnabled = true;
  57.  
  58. _endpoint = new UserEndpoint(_collabPlatform, settings);
  59. _endpoint.BeginEstablish(UserEndpointEstablishCompleted, _endpoint);
  60.  
  61. }
  62.  
  63.  
  64. private static void UserEndpointEstablishCompleted(IAsyncResult ar)
  65. {
  66.  
  67. try
  68. {
  69. var currentEndpoint = ar.AsyncState as LocalEndpoint;
  70. <strong>currentEndpoint.EndEstablish(ar);</strong>
  71.  
  72. //Once the endpoint is in place, wait for a conversation to arrive.
  73. _endpoint.RegisterForIncomingCall<InstantMessagingCall>(HandleInstantMessagingCall);
  74. }
  75. catch (Exception ex)
  76. {
  77. Console.WriteLine("ERROR : " + ex);
  78. }
  79.  
  80.  
  81. }
  82.  
  83. private static void HandleInstantMessagingCall(object sender, CallReceivedEventArgs<InstantMessagingCall> e)
  84. {
  85. if (e.ToastMessage != null && e.ToastMessage.HasTextMessage)
  86. {
  87. // Store the incoming message text.
  88. incomingMessage = e.ToastMessage.Message;
  89. // Signal that we have a message.
  90. incomingMessageWaiter.Set();
  91. }
  92.  
  93. call = e.Call;
  94. call.InstantMessagingFlowConfigurationRequested += HandleInstantMessagingFlowConfigurationRequested;
  95. call.BeginAccept(EndCallAccept, null);
  96. }
  97.  
  98. private static void EndCallAccept(IAsyncResult ar)
  99. {
  100. call.EndAccept(ar);
  101. }
  102.  
  103. private static void HandleInstantMessagingFlowConfigurationRequested(object sender, InstantMessagingFlowConfigurationRequestedEventArgs e)
  104. {
  105. flow = e.Flow;
  106. flow.MessageReceived += HandleFlowMessageReceived;
  107. flow.StateChanged += HandleFlowStateChanged;
  108. }
  109.  
  110. private static void HandleFlowMessageReceived(object sender, InstantMessageReceivedEventArgs e)
  111. {
  112. if (e.HasTextBody)
  113. {
  114. // Store the incoming message text.
  115. incomingMessage = e.TextBody;
  116. // Signal that we have a message.
  117. incomingMessageWaiter.Set();
  118. }
  119.  
  120. }
  121.  
  122.  
  123. static void HandleFlowStateChanged(object sender, MediaFlowStateChangedEventArgs e)
  124. {
  125. if (e.State == MediaFlowState.Active)
  126. {
  127. // Signal that the flow is ready.
  128. flowWaiter.Set();
  129. }
  130. }
  131.  
  132. private static void SendReplyMessage(string reply)
  133. {
  134. // Send the message to the requestor.
  135. flow.BeginSendInstantMessage(reply, EndBeginSendInstanceMessage, null);
  136. }
  137.  
  138. private static void EndBeginSendInstanceMessage(IAsyncResult ar)
  139. {
  140. flow.EndSendInstantMessage(ar);
  141.  
  142. // Having sent the message, terminate the conversation
  143. flow.Call.Conversation.BeginTerminate(EndBeginTerminate, flow.Call.Conversation);
  144. }
  145.  
  146. private static void EndBeginTerminate(IAsyncResult ar)
  147. {
  148. Conversation conversation = (Conversation)ar.AsyncState;
  149. conversation.EndTerminate(ar);
  150.  
  151. _OKToQuit = true;
  152. }
  153. }
  154. }
  155.  
  156. ERROR : ErrorCode=-2146893022
  157. FailureReason=IncorrectNameInRemoteCertificate
  158. LocalEndpoint=100.77.120.70:53578
  159. RemoteEndpoint=52.176.63.216:5061
  160. RemoteCertificate=<null>
  161. Microsoft.Rtc.Signaling.TlsFailureException:The target principal name is incorrect ---> Microsoft.Rtc.Internal.Sip.TLSException: outgoing TLS negotiation failed; Wrong target principal name configured. HRESULT=-2146893022
  162. at Microsoft.Rtc.Internal.Sip.TlsTransportHelper.HandleNegotiationFailure(Int32 status, Boolean incoming)
  163. at Microsoft.Rtc.Internal.Sip.TlsTransportHelper.OutgoingTlsNegotiation(TransportsDataBuffer receivedData, TransportsDataBuffer& pDataToSend)
  164. at Microsoft.Rtc.Internal.Sip.TlsTransportHelper.NegotiateConnection(TransportsDataBuffer receivedData, TransportsDataBuffer& pDataToSend)
  165. at Microsoft.Rtc.Internal.Sip.TlsTransport.DelegateNegotiation(TransportsDataBuffer receivedData)
  166. at Microsoft.Rtc.Internal.Sip.TlsTransport.OnReceived(Object data)
Add Comment
Please, Sign In to add comment