public static UserEndpoint ConnectLyncServer(string userSipUri, string lyncServer, bool usingSso, string username, string password) { // Create the Lync Server UserEndpoint and attempt to connect to Lync Server Console.WriteLine("{0} Connecting to Lync Server... [{1}]", username, lyncServer); // Use the appropriate SipTransportType depending on current Lync Server deployment ClientPlatformSettings platformSettings = new ClientPlatformSettings("PersistentChat.Test", SipTransportType.Tls); CollaborationPlatform collabPlatform = new CollaborationPlatform(platformSettings); collabPlatform.AllowedAuthenticationProtocol = SipAuthenticationProtocols.Ntlm; // Initialize the platform collabPlatform.EndStartup(collabPlatform.BeginStartup(null, null)); // You can also pass in the server's port # here. UserEndpointSettings userEndpointSettings = new UserEndpointSettings(userSipUri, lyncServer); // When usingSso is true use the current users credentials, otherwise use username and password userEndpointSettings.Credential = usingSso ? SipCredentialCache.DefaultCredential : new NetworkCredential(username, password); UserEndpoint userEndpoint = new UserEndpoint(collabPlatform, userEndpointSettings); // Login to Lync Server. userEndpoint.EndEstablish(userEndpoint.BeginEstablish(null, null)); if (PersistentChatServerUri == null) { // Extract default Persistent Chat pool uri from inband ProvisioningData provisioningData = userEndpoint.EndGetProvisioningData(userEndpoint.BeginGetProvisioningData(null, null)); PersistentChatServerUri = new Uri(provisioningData.PersistentChatConfiguration.DefaultPersistentChatUri); Console.WriteLine("\t-- {0}PersistentChatServerUri:{1}", username, PersistentChatServerUri); } Console.WriteLine("\t{0} Connecting>>>>Success", username); return(userEndpoint); }