-
-
Save christiannagel/3e7482375ba3f04762359f9ac86c4b43 to your computer and use it in GitHub Desktop.
Sending messages to the app service with UWP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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