Revision #4

You are currently reviewing an older revision of this page.
Go to current version
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.

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:

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.

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.

_lyncClient = Microsoft.Lync.Model.LyncClient.GetClient();
MessageBox.Show(“Microsoft Lync is not running on your machine.”, “Error Message”, MessageBoxButton.OK, MessageBoxImage.Error);

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.

result = >
if (result.IsCompleted)
LogEvent(“SignInCallback”, “Signing in to Lync”);
InitializeClient(); // Setup application logic
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:
Revert to this revision