Skip to content

Instantly share code, notes, and snippets.

@christiannagel
Created October 6, 2018 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christiannagel/3e7482375ba3f04762359f9ac86c4b43 to your computer and use it in GitHub Desktop.
Save christiannagel/3e7482375ba3f04762359f9ac86c4b43 to your computer and use it in GitHub Desktop.
Sending messages to the app service with UWP
private async void OnAppService(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
// don't dispose the connection now! This closes the app!
if (_appServiceConnection == null)
{
_appServiceConnection = new AppServiceConnection
{
AppServiceName = "com.cninnovation.desktopbridgesample",
PackageFamilyName = "6d982834-6814-4d82-b331-8644a7f54418_2dq4k2rrbc0fy"
};
AppServiceConnectionStatus status = await _appServiceConnection.OpenAsync();
if (status != AppServiceConnectionStatus.Success)
{
throw new InvalidOperationException($"App service connection failed with status {status.ToString()}");
}
}
var valueSet = new ValueSet
{
{ "command", "data" },
{ "data", textData.Text }
};
AppServiceResponse response = await _appServiceConnection.SendMessageAsync(valueSet);
if (response.Status == AppServiceResponseStatus.Success)
{
string answer = string.Join(", ", response.Message.Values.Cast<string>().ToArray());
await new MessageDialog($"received {answer}").ShowAsync();
}
else
{
await new MessageDialog("error send").ShowAsync();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment