Altova MobileTogether Designer

Messaging in the UWP App

Home Prev Top Next

The broad stages for messaging would be as follows:

 

1.Data is communicated from the UWP app to the solution (displayed in a SolutionView control of the UWP page).

2.The solution sends the data to the solution's workflow on MobileTogether Server, where it is processed in the usual way.

3.Results are returned to the SolutionView control, where they can be (i) displayed as part of the solution, and/or (ii) passed back to the UWP app for display or further processing.

 

Messaging mechanism

A message that is sent from a UWP app to the server is called an embedded message. The messaging mechanism uses three MobileTogether features:

 

The OnEmbeddedMessage event, which is available as a page event;

The $MT_EMBEDDEDMESSAGE JSON page source, which is generated automatically if at least one action is defined for the OnEmbeddedMessage event;

The Embedded Message Back action, which sends a serialized JSON string as a return message;

 

How these features are used for messaging in the UWP app is as follows:

 

SolutionView control now has a method ProcessEmbeddedMessage(msg) that (i) populates the $MT_EMBEDDEDMESSAGE JSON page source, and (ii) triggers the page event OnEmbeddedMessage.

SolutionView control now has an event named EmbeddedMessage that is triggered when, in the hosted solution, the Embedded Message Back action is executed. This event can be processed synchronously or asynchronously, for example, by using the standard UWP deferral mechanism as listed below.

 

void EmbeddedMessage(object sender, EmbeddedMessageEventArgs e)

{

var deferal = e.GetDeferral();

... Do some parallel processing of e.Message ...

deferal.Complete();

}

 

Messaging: step-by-step

The steps given below provide a detailed look at the messaging process.

 

UWP app to solution to MT Server

 

1.The ProcessEmbeddedMessage(msg) method in your code can be used to transfer data from the UWP app to the SolutionView control. The data must be sent as a serialized JSON object. (If your data is in XML format, then the XML document must be wrapped inside a JSON object.)

2.The targeted solution must have an OnEmbeddedMessage event that has at least one action defined for it. In this case, when an embedded message reaches the solution, a $MT_EMBEDDEDMESSAGE JSON page source is created automatically and populated. The page source will have a root element named json, and its structure and content will come from the embedded message.

3.On the server, the $MT_EMBEDDEDMESSAGE JSON page source can be processed via actions of the OnEmbeddedMessage event or in any other way. This completes the first half of the transfer, from UWP app to MobileTogether Server. Processed data can now be sent back to the solution.

 

MT Server to solution to UWP app

 

4.The Embedded Message Back action sends a return message to the SolutionView control in the form of a serialized JSON string. In defining the action, you can specify the message that you want to send. For example, in the screenshot below, the action specifies that the message to be sent back is the entire data structure stored in the $MT_EMBEDDEDMESSAGE JSON page source: that is, the tree's json node and its contents.

MTActionEmbeddedMsgBackUWP

5.When the solution's Embedded Message Back action is executed, the SolutionView control's EmbeddedMessage event is triggered. The embedded message received by the SolutionView control can now be processed by the code of your UWP app.

 

© 2018-2024 Altova GmbH