Getting Started With The Lync 2010 Managed API - SIGN IN

Getting Started With The Lync 2010 Managed API - SIGN IN

Applications use the Lync API to interact with the running instance of the Lync client. The Lync API reuses the connection that the running instance of the Lync client has to the Lync infrastructure, making for a much easier development experience where you are not responsible for maintaining this connection or the underlying logic of starting and participating in conversations across the connection.

Setting Up Your Development Environment
:
The Lync API is installed as part of the Microsoft Lync 2010 SDK, which also includes the Lync controls. In a default installation, the Lync SDK is installed at C:\Program Files (x86)\Microsoft Lync\SDK .

Microsoft Lync 2010:
The Lync client must be installed in order for you to programmatically interact with it using the Lync API. The user doesn't necessarily have to be initially signed in to the Lync client to start; you can use the Lync API to programmatically sign in the current user.

Assemblies:
You can fi nd the Lync API assemblies in C:\Program Files (x86)\Microsoft Lync\SDK\Assemblies , where different assemblies are available for WPF (and Windows Forms) and Silverlight applications. When adding the necessary references, make sure to add them from the correct folder. Add references to the following assemblies:
Microsoft.Lync.Model.dll
Microsoft.Lync.Utilities.dll

Interacting with the Running Instance of the Lync Client:
When integrating communications features into your application using the Lync API, you are responsible for managing the lifecycle of the Lync client. If the Lync client is not signed in, you can use the Lync API to sign in to the running instance. Your application must also react accordingly when the state of the Lync client changes; for example, the user signs out or loses network connectivity and is disconnected. In this section, you learn how to sign in to the running instance of the Lync client and wire up the necessary events so that your application can handle changes in the state of the Lync client.

Signing into the Lync Client Instance:
To access functionality exposed by the Lync API throughout your application, add a module level of type LyncClient representing the running instance of the Lync client.

Code:
private Microsoft.Lync.Model.LyncClient _lyncClient;

You can access the running instance of the Lync client throughout the application; for example, to sign in or out, wire up event handlers for changes in the state of the Lync client, and access other features such as Automation.

When your application loads, you can get a reference to the running instance of the Lync client by calling the static GetClient method of the Microsoft.Lync.Model.LyncClient class. Set the module level variable lyncClient to the return value of the GetClient method. Be sure to wrap the call to GetClient in a try/catch block as shown in the following code; an exception is raised if the Lync client is not installed or not running.

Code:
try
{
_lyncClient = Microsoft.Lync.Model.LyncClient.GetClient();
}
catch
{
MessageBox.Show(“Microsoft Lync is not running on your machine.”, “Error Message”, MessageBoxButton.OK, MessageBoxImage.Error);
Close();
}

Signing In with the Current User's Credentials:
After checking that the Lync client is installed and running on the user's machine, the next step is to programmatically sign the user into Lync. Signing in the user programmatically has the same effect as the user signing in by interacting directly with the Lync client.

Call BeginSignIn on the instance of LyncClient to sign into the running instance of the Lync client, as shown in the following code. The BeginSignIn method takes in userUri , domainAndUsername , and password parameters to sign in a user with specifi c credentials. Passing in null for these parameters will sign in the user who is currently logged into Windows.

Code:
_lyncClient.BeginSignIn(
null,
null,
null,
result = >
{
if (result.IsCompleted)
{
_lyncClient.EndSignIn(result);
LogEvent(“SignInCallback”, “Signing in to Lync”);
InitializeClient(); // Setup application logic
}
else
{
LogEvent(“SignInCallback”, “Count not sign in to Lync”);
}
},
“Local user signing in” as object);

Alternatively, you can specify credentials for the user to sign in as the following:
_lyncClient.BeginSignIn(
“m.sakr@egyptnetwork.com”,
“go\\m.sakr”,
“pass@word1”,
...
Leave a Comment
  • Please add 7 and 2 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Yagmoth555 edited Revision 6. Comment: Hi, excellent article !, adding language tag and fixing title casing

  • Fernando Lugão Veltem edited Revision 2. Comment: alter tags and added to Lync Server survival guide

Page 1 of 1 (2 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Fernando Lugão Veltem edited Revision 2. Comment: alter tags and added to Lync Server survival guide

  • Yagmoth555 edited Revision 6. Comment: Hi, excellent article !, adding language tag and fixing title casing

Page 1 of 1 (2 items)