Implementing the custom messaging interface
In your Visual Studio Tools add-in that runs on the server, you will implement methods for the IWCCustomMessagingAddIn interface. These additional methods provide support for the messaging that is used for custom rendering.
Implementing the interface
To implement this interface, use the following procedure.
Open the solution for your Visual Studio Tools integration.
If it isn't already open, use Visual Studio to open the solution for your add-in.
Open the file that implements the IDexterityAddIn interface.
Typically, this will be the GpAddIn.cs or GpAddIn.vb file for a standard Visual Studio Tools project.
Add code for the IWCCustomMessagingAddIn interface.
For a C# integration, add the IWCCustomMessagingAddIn interface to the same class that implements the IDexterityAddIn interface. This is shown in the following illustration:
After you have added the interface name, right-click the interface name in the code editor, point to Implement Interface, and then choose Implement Interface. The methods for the interface are automatically added to the class. This is shown in the following illustration.
For a Visual Basic integration, add the IWCustomMessagingAddIn interface to the Implements statement for the same class that implements the IDexterityAddIn interface. When you press Enter at the end of the Implements statement, the methods for the interface are automatically added to the class. This is shown in the following illustration.
Adding code to the methods
You will add code to the methods for the interface as you develop the integration.
- First, you will initialize messaging, which is described later in this section.
- Later in the development process you will add code to the ProcessMessage() method to handle messages that the add-in receives from the web client. Information about this is found in Receiving messages.
- Near the end of the development process you will add code to the Recover() method, which is responsible for restoring the state of the Visual Studio Tools add-in when a user reconnects to a web client session. Information about implementing this method is found in Session recovery.
Initializing messaging
The first method to implement in the IWCCustomMessagingAddIn interface is InitializeMessaging(). This method establishes the communication that allows the server-side Visual Studio Tools add-in to send and receive messages from the Silverlight component.
If you are using C# for your integration, begin by adding a static variable to the class that contains the InitializeMessaging() method. This static variable will store the proxy that is used to send and receive messages. The following example shows the static variable for the proxy:
// The proxy for communication between the web client and the server public static IWCCustomMessagingProxy proxy;
In the InitializeMessaging() method, add the following code to create an instance of the proxy:
public void InitializeMessaging(IWCCustomMessagingProxy proxy) { GPAddIn.proxy = proxy; }
If you are using Visual Basic for your integration, the code is similar. Begin by adding a public shared variable to the class that contains the InitializeMessaging() method. The following example shows the shared variable for the proxy:
Public Shared proxy As IWCCustomMessagingProxy
In the IntializeMessaging() method, add the following code to create an instance of the proxy:
Public Sub InitializeMessaging(proxy As Microsoft.Dexterity.Bridge.IWCCustomMessagingProxy) Implements Microsoft.Dexterity.Bridge.IWCCustomMessagingAddIn.InitializeMessaging GPAddIn.proxy = proxy End Sub