Microsoft Lync’s Development Secret: it’s easy!
Right, before I go any further I should probably clarify that title, in case my boss or CEO is reading this!
There’s a certain use-case of Lync development which lots of non-Lync developers will find themselves in. Microsoft have realised this and have produced a set of controls that make it very easy for these developers to get what they need to done, without needing to invest hours in learning yet another concept.
You’re a developer. You’re not a Lync developer, in fact you spent a very confusing half hour with your boss this morning when he was talking Lync and you were talking Linq, and you couldn’t understand how the company could possibly have “bought” it, much less that they had “rolled it out” or that it was “on customer’s desktops”. Let’s be honest, you were just surprised someone out of IT had heard of Linq.
Anyway – so now your customers have this new IM/presence/talky thing, and it looks great in Outlook, and it looks great in Sharepoint, and now your users have some questions:
- Why doesn’t it work with the people on the company’s Intranet site?
- Why doesn’t it work with the in-house stock management system?
Well, of course it’s not going to work. Those are in-house, custom-built apps. It’s going to take you months to try and integrate all that communication tech into your apps, and quite frankly, you have better things to do than learn how to integrate yet another technology.
Microsoft to the Rescue
It turns out you’re in luck. This is precisely the scenario Microsoft thought you (and thousands like you) would be in. If the following is true for you, prepare to be helped:
- you (or your users) have Lync running on the desktop.
- your in-house apps are built in either WPF or Silverlight.
- you don’t want to know too much about exactly how Lync works.
- you don’t want to have to learn the SIP protocol stack (you don’t, I guarantee it).
For you, Microsoft has made available a set of WPF and Silverlight controls, each of which encapsulates a bit of functionality of the Lync client, all nicely packaged up and abstracted. You can quite literally just drop these into existing applications and they will work fine.
This is because of the first pre-requisite above: needing Lync running on the desktop. The controls attach to the running Lync instance, so avoiding all the hard work of having to create and manage a connection.
To start, download and install the Lync 2010 SDK or the Lync 2013 SDK, depending on what version of Lync you and your user have. Once you’ve installed this, when you create a new project in Visual Studio you’ll notice that you have two extra project types: Lync Silverlight Application and Lync WPF Application.
I’m going to create a Lync WPF Application, so if you’re playing along at home choose this project type and create a new project.
This will create a new WPF application with a couple of differences. The most obvious is that the sample page created has a control on it, which looks a bit like a Lync contact card:
In fact that’s exactly what it is. If you look at the XAML code for this page you’ll see it:
Now, you don’t need to know anything about Lync development, or even very much about XAML to see that there’s a control displaying the Presence of someone called John. Anyone familiar with XAML will also notice the text block binding to this data to show the user’s display name.
By now any developers working through this will already have been overcome by the desire to change the SIP address to their own and hit F5, so if anyone else would like to stop reading, fire up Visual Studio and give this a go, feel free to get it all out the way now.
In all seriousness though, this is pretty cool. With a minimal amount of work you can show a user’s Lync contact card in your own WPF application. By itself that’s OK, but if you have areas of your application where one or more users are prominent (for instance, the sales manager of a region being displayed) then it might make sense to use this control here. There’s no reason at all why you can’t bind the Source property to some data somewhere to show the right contact, or set it programatically.
It’s worth pointing out that the control behaves exactly like the full Lync presence indicator, in fact it IS the full Lync presence indicator. Toggling the presence updates in real-time, all the buttons to email, IM, call etc., work and hovering over the contact displays the full card:
But wait, there’s more!
In all the excitement, I expect you haven’t noticed that the Toolbox has an extra section, containing a whole selection of Lync-based controls:
Just looking through that list you can see there’s a whole variety of different controls there to fit your integration needs. In particular you may find the CustomContactList and CustomContactListItem controls useful wherever you have lists of people in your application. Or, depending on how your controls are already built, you may just wish to use the simple PresenceIndicator to give immediate availability feedback.
If you need to you can even break down the supplied controls and change how they look and behave. There’s information on doing this on MSDN. Just make sure there’s a good reason for altering the look and behavior because users are used to seeing and using the standard controls and changing this might confuse them, especially as the Lync application will continue to show the standard behavior.
In this walk-through I’ve shown you how to add Lync components to a brand new project. Obviously, when you come to integrate, you’ll be adding components to an existing project. The process is the same, but you’ll need to add some references before you can use the controls. WPF and Silverlight use different DLLs.
The references you’ll need to add are:
If you’ve installed the SDK then you should find these in the Microsoft Lync / SDK / Assemblies folder. Choose either Desktop or Silverlight depending on your project. If you have any problem finding these, just check in the sample project for the references used there and their location. There’s more information and detail for doing this in both WPF and Silverlight projects in the MSDN article Application Strategies in Lync 2010 Control Applications.