I have a fulltrust desktop-bridge application. There are lots of data flow between UWP and WPF (Win32) apps. I want to deploy different appService for each task. Is it possible to use multiple appService? Does UWP support multiple appService connection at the same time where each specific appservice will be worked independently?
For example: I have multiple task like device-discover, file-transfer etc. I want to declare two different appService like bellow for each task.
<uap:Extension Category="windows.appService">
<uap:AppService Name="FileTransferAppService" />
</uap:Extension>
<uap:Extension Category="windows.appService">
<uap:AppService Name="DeviceDiscoverAppService" />
</uap:Extension>
Handling each connection event from OnBackgroundActivation for UWP side:
protected override async void OnBackgroundActivated(BackgroundActivatedEventArgs args)
{
base.OnBackgroundActivated(args);
if (args.TaskInstance.TriggerDetails is AppServiceTriggerDetails details)
{
if(details.CallerPackageFamilyName == Package.Current.Id.FamilyName)
{
if (details.AppServiceConnection.AppServiceName.Equals("FileTransferAppService"))
{
//Handle File transfer related task.
// connection established from the fulltrust process
FT_AppServiceDeferral = args.TaskInstance.GetDeferral();
args.TaskInstance.Canceled += OnFTService_TaskCanceled;
FT_Connection = details.AppServiceConnection;
FT_AppServiceConnected?.Invoke(this, args.TaskInstance.TriggerDetails as AppServiceTriggerDetails);
}
else
{
//Handle Device Discover related task.
// connection established from the fulltrust process
DD_AppServiceDeferral = args.TaskInstance.GetDeferral();
args.TaskInstance.Canceled += OnDDService_TaskCanceled;
DD_Connection = details.AppServiceConnection;
DD_AppServiceConnected?.Invoke(this, args.TaskInstance.TriggerDetails as AppServiceTriggerDetails);
}
}
}
}
Establishing individual connection from WPF side:
ft_connection = new AppServiceConnection();
ft_connection.AppServiceName = "FileTransferAppService";
ft_connection.PackageFamilyName = Package.Current.Id.FamilyName;
ft_connection.RequestReceived += ft_Connection_RequestReceived;
ft_connection.ServiceClosed += ft_Connection_ServiceClosed;
dd_connection = new AppServiceConnection();
dd_connection.AppServiceName = "DeviceDiscoverAppService";
dd_connection.PackageFamilyName = Package.Current.Id.FamilyName;
dd_connection.RequestReceived += dd_Connection_RequestReceived;
dd_connection.ServiceClosed += dd_Connection_ServiceClosed;
I have tried above but not getting any RequestReceived event for the both connection at a time from WPF side. I’m not sure does uwp support parallel appService connection at a time or not?
I have another question, if we elevate another WPF application under the same package, will it be able to stablish appService connection with UWP app?
Thanks in advance. Any help will be appreciated.
When you register a service, only one AppService can be defined in the package manifest, if you define multiple AppServices, UWP can only connect to one of them and cannot access them at the same time, you can use multiple WPF applications to access same AppService.