我正在尝试使用AppServices在两个应用之间进行通信。但是,似乎通信仅限于以下内容:客户端应用程序向AppService发送一些数据,AppService返回自己的数据。
在客户端发起请求的情况下,是否无法在客户端中使用事件侦听器,或者从服务向客户端发送信息的任何其他方式?
由于
答案 0 :(得分:0)
是的,但是应用程序需要打开连接。打开连接后,挂钩事件处理程序到事件RequestReceived
gpsService = new AppServiceConnection();
gpsService.AppServiceName = "nl.sparked.gpsappservice";
gpsService.PackageFamilyName = "b4619a2e-4aa1-4b84-b444-c2c2750cb4c8_5q3b35137xmx2";
RemoteSystemConnectionRequest connectionRequest = new RemoteSystemConnectionRequest(remoteSystem);
var status = await gpsService.OpenRemoteAsync(connectionRequest);
if (status == AppServiceConnectionStatus.Success)
{
gpsService.RequestReceived += GpsService_RequestReceived;
}
在您的appservice中,您可以发送数据:
var details = taskInstance.TriggerDetails as AppServiceTriggerDetails;
appServiceconnection = details.AppServiceConnection;
appServiceconnection.SendMessageAsync(new ValueSet());