Sending messages
Messages sent between the web client and the server are used to keep the Silverlight application synchronized with the Visual Studio Tools add-in that is running on the server. With the custom rendering, you are responsible for all of the messages that are sent between the web client and the server for your add-in.
How messages are used
The messages that keep the Silverlight application synchronized with the Visual Studio Tools add-in are used in several ways:
- Some messages will contain the data that is retreived by the add-in running on the server and then sent to the web client to be displayed in the Silverlight windows.
- Some messages will contain data that is entered by the user on the web client, and then transferred to the server to be processed by the add-in.
- Some messages indicate actions to be performed within the integration, such as opening or closing a window.
- Some messages will indicate actions the user performed in the web client, such as clicking a button in a window.
Hint: For a specific example of the messages used in an integration, see Salesperson Analysis which lists the messages that the Salesperson Analysis sample application uses to implement custom rendering.
Message structure
Each message that is sent between the web client and server has the type WCVstCustomMessage. It has the following parameters:
Source This is a string value that must contain the namespace and class of the sender.
Destination This is a string value that must contain the namespace and class for the message processor method in the destination.
Description This is a string that contains a description of the message. It is used to help identify the message. In some cases, it can contain the information to be sent by the message.
Data This is a byte stream value that contains the data for the message. Typically, this is a serialized value. The contents of the byte stream is automatically compressed to make the data transfer more efficient.
Message proxy
A message proxy is used to send messages between the Silverlight code that is running on the web client and the Visual Studio Tools add-in that is running on the server. In the Visual Studio Tools add-in, you added code to create this proxy when you implemented support for custom messages as described in Implementing the custom messaging interface. The Microsoft Dynamics GP Web Client (Silverlight) project template already contains code that implements the message proxy.
The proxy has two methods that are used to send messages. The SendMessage() method sends a single message from the web client to the server, or from the server to the web client. The SendMessages() method sends a collection of messages in a single operation. In some cases, it's more efficient to send messages as a collection, rather than sending several messages separately. For example, if you're sending a large number of fields to be displayed in a window, it may be more efficient to send all of the fields at one time using the SendMessages() method.
It's important that your Visual Studio Tools add-in uses the message proxy only when it is being used in for the web client. If you make calls to the message proxy and the desktop client is being used, runtime errors will occur. We recommend that you use the DexRuntimeGetClientType() helper function to determine whether the web client is being used before you send messages with the message proxy.
The Source and Destination properties are very important when sending messages. The values of these properties are used by Microsoft Dynamics GP to direct the message to the correct Visual Studio Tools add-in or Silverlight application. The combination of the root namespace and the class define a unique indentifier, helping to ensure that message can be routed properly. The following table lists the namespace and class that contains the ProcessMessage() method for the Visual Stuio Tools add-in and the Silverlight component of the Salesperson Analysis sample. It also lists the Source and Destination values that are used when sending messages from the component. Notice the period (.) that is included to separate the namespace and class.
Visual Studio Tools add-in |
Silverlight component |
|
---|---|---|
Namespace |
SalespersonAnalysis |
SalespersonAnalysisSL |
Class |
GPAddIn |
GPWCAddIn |
Source |
SalespersonAnalysis.GPAddIn |
SalespersonAnalysisSL.GPWCAddIn |
Destination |
SalespersonAnalysisSL.GPWCAddIn |
SalespersonAnalysis.GPAddIn |