Application Registration for Lync 2010 Contextual Applications
Summary: Use Run-Time Registration and Install Registration to identify and configure Microsoft Lync 2010 contextual applications, and help secure the data that is shared in contextual conversations.
Applies to: Microsoft Lync 2010 SDK | Microsoft Lync 2010 | Published: January 2011 | Provided by: John Clarkson, Microsoft | About the Author
Contents
Introduction
Start the Conversation
Join the Conversation
Run the Two Applications
Conclusion
Additional Resources
Introduction
Install Registration and Run-Time Registration are complementary. In this article you learn how to use the two registration types together to dynamically configure a Microsoft Lync 2010 contextual application and secure the data that is used in the conversation. The sending computer starts a conversation using an IM message that contains contextual data. Run-Time Registration will register the application and then open the application in the Lync Conversation Window Extension. The receiving computer will join the conversation, and then use Run-Time Registration to identify the contextual application and secure access to the data that is used in the conversation. Before you try the example described in this scenario, review the prerequisites appearing in Walkthrough: Presence Hello World.
Run-Time Registration and Install Registration scenario
Comparing Registration Types
Run-Time Registration does not change Microsoft Windows registry entries. Run-Time Registration creates a new application package that exists in the Lync 2010 registration pool until one of three events occur:
Application is unregistered.
Application stops running.
User signs out to end session.
Run-Time Registration can exist without Install Registration. However, if you use Run-Time Registration consider using Install Registration also. In a case in which Run-Time Installation and Install Registration occur with the same application ID, Run-Time Registration overrides Install Registration during the life of the session. When the user signs out, the Run-Time Registration instance resets and the Install Registration instance starts.
Technique |
Description |
---|---|
Install Registration |
|
Run-Time Registration |
|
Use Run-Time Registration to Improve Data Security
Run-Time Registration provides additional security around the GUID used in registration. The GUID can only be used in the same thread where Run-Time Registration is used. If another thread tries to use that GUID to identify the contextual application, access the contextual context, or open the Lync Conversation Window Extension, an access denied exception is thrown.
To use the GUID in more than one thread, use Install Registration. In this case remember that your contextual data can be accessed by other applications that run on the same computer as long as they have access to Microsoft Lync 2010 API.
Start the Conversation
In this example, the sending application starts a conversation with an IM message and contextual data. The code-behind uses Run-Time Registration to specify and configure the application that opens in the Lync Conversation Window Extension.
Use Run-Time Registration on the computer that starts the conversation to specify and to configure the contextual application that runs during the conversation. On the computers that receive the message, use Run-Time Registration to register the application and secure the contextual data that is used in the conversation.
To create the Lync Application
Create a new project with the Lync Silverlight Application template. Use the following code in the Page.xaml.cs file.
ApplicationRegistration myApplicationRegistration;
ConversationWindow cWindow;
public Page()
{
InitializeComponent();
// Call this method to perform Run-Time
// Registration using the ApplicationRegistration class.
PerformRunTimeRegistration();
// Conversation participant list.
// Update the example URL with a valid value.
List<string> ConversationParticipantList = new List<string>();
ConversationParticipantList.Add("sip:barbara@contoso.com");
// Declare instance of Dictionary to pass the conversation context data.
Dictionary<AutomationModalitySettings, object> conversationContextData = new Dictionary<AutomationModalitySettings, object>();
// Provide Conversation context: First IM Message.
conversationContextData.Add(AutomationModalitySettings.FirstInstantMessage, "Contoso Application Context");
// Provide Conversation context: Send first IM message immediately after the conversation starts.
conversationContextData.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, true);
// Provide Conversation context: Set the Application ID of the registered contextual application.
conversationContextData.Add(AutomationModalitySettings.ApplicationId, "{55058F71-6ACF-48D0-B20E-BC7668695371}");
// Provide Conversation context: Set contextual data.
conversationContextData.Add(AutomationModalitySettings.ApplicationData, "1234");
// Create an Automation object.
Automation myUIAuto = LyncClient.GetAutomation();
// Start the conversation.
IAsyncResult beginconversation = myUIAuto.BeginStartConversation(
AutomationModalities.InstantMessage
, ConversationParticipantList
, conversationContextData
, BeginConversationCallBack
, myUIAuto);
}
// Perform Run-Time Registration using the ApplicationRegistration class.
void PerformRunTimeRegistration()
{
// Ensure that this GUID matches the registry value entered in the previous section.
string guid = "{55058F71-6ACF-48D0-B20E-BC7668695371}";
string appname = "Contoso Test Application";
myApplicationRegistration = LyncClient.GetClient().CreateApplicationRegistration(guid, appname);
string path = @"C:\Data\sampleSLEmbed.html";
// Set the properties of the Lync Conversation Window Extension.
// Ensure that the internalURL parameter is valid on your computer.
myApplicationRegistration.SetExtensibilityWindowProperties(
path
, "https://msn.com"
, ConversationWindowExtensionSize.Medium);
// Register the application.
this.myApplicationRegistration.AddRegistration();
}
// Notify the Automation object and ConversationWindow
// that the conversation started.
private void BeginConversationCallBack(IAsyncResult ar)
{
Automation _automation = ar.AsyncState as Automation;
cWindow = _automation.EndStartConversation(ar);
}
// End the conversation.
private void EndConversation_Click(object sender, EventArgs e)
{
try
{
// Unregister Run-Time Registration for application context.
myApplicationRegistration.RemoveRegistration();
this.cWindow.Close();
}
catch (Exception) { }
}
}
Create the Registry Entry
You can use Registry Editor to register any applications that you select or none at all. Regardless, Lync uses the GUID and the application that is specified by Run-Time Registration. Run-Time Registration overrides Install Registration.
[HKEY_CURRENT_USER\Software\Microsoft\Communicator\ContextPackages\{55058F71-6ACF-48D0-B20E-BC7668695371}]
"InternalURL"="Path to your Silverlight .html file "
"Name"="Blue Yonder Airlines"
Join the Conversation
The receiving application in this example is a Microsoft Silverlight application that is running in the Lync Conversation Window Extension. When the user clicks a button, contextual data that accompanies the message appears in a text box.
Create the Lync Application
In the Page.xaml file, add a button and a text box control to the design pane. Use LoggerTextBox as the name of the text box control. Use GetAppData as the name of the button control. You can choose your own control names, but LoggerTextBox and GetAppData appear in the following sample code.
Note
Before you use the following code, you must create a new project that is based on the Lync Silverlight Application template, and select the option to host the Silverlight application in a website.
Sample XAML Code
<TextBox Height="23" HorizontalAlignment="Left" Margin="25,30,0,0" Name="LoggerTextBox" VerticalAlignment="Top" Width="120" />
<Button Click="GetAppData_Click" Content="Button" Height="23" HorizontalAlignment="Left" Margin="48,81,0,0" Name="button1" VerticalAlignment="Top" Width="75" />
Sample C# Code
ApplicationRegistration myApplicationRegistration;
ConversationWindow cWindow;
Conversation _conversation;
string AppId = "{55058F71-6ACF-48D0-B20E-BC7668695371}";
public Page()
{
InitializeComponent();
Initialize();
}
private void Initialize()
{
_conversation = (Conversation)Microsoft.Lync.Model.LyncClient.GetHostingConversation();
// Call this method to perform Run-Time
// Registration using the ApplicationRegistration class.
PerformRunTimeRegistration();
}
private void GetAppData_Click(object sender, RoutedEventArgs e)
{
LoggerTextBox.Text = _conversation.GetApplicationData(AppId);
}
// Perform Run-Time Registration using the ApplicationRegistration class
void PerformRunTimeRegistration()
{
// Ensure that this GUID matches the registry value entered in the previous section.
string guid = AppId;
string appname = "Contoso Test Application";
myApplicationRegistration = LyncClient.GetClient().CreateApplicationRegistration(guid, appname);
// Register the application.
this.myApplicationRegistration.AddRegistration();
}
// End the conversation.
private void EndConversation_Click(object sender, EventArgs e)
{
try
{
// Unregister Run-Time Registration for application context.
myApplicationRegistration.RemoveRegistration();
this.cWindow.Close();
}
catch (Exception) { }
}
Create the Registry Entry
Use Registry Editor and Install Registration to register the application described in this section. Install Registration is required on the receiving computer. The GUID specified in Run-Time Registration on both computers must be identical to the Install Registration instance on the receiving computer.
[HKEY_CURRENT_USER\Software\Microsoft\Communicator\ContextPackages\{55058F71-6ACF-48D0-B20E-BC7668695371}]
"InternalURL"="Path to your Silverlight .html file "
"Name"="Blue Yonder Airlines"
Run the Two Applications
When the sending application starts to run, the sending application uses Run-Time Registration to specify and configure the application that appears in the Lync Conversation Window Extension. When the message is opened on the receiving computer, Run-Time Registration occurs there too. Contextual data sent with the message is available on the receiving computer, but only within the thread identified by the conversation GUID.
Conclusion
Use Run-Time and Install Registration together to provide flexibility when you configure applications, and to improve data security within the Lync conversation.
Additional Resources
For more information, see the following resources:
About the Author
John Clarkson is a technical writer with the Microsoft Lync product team.