边缘扩展本机消息:如果没有响应发送回边缘浏览器/扩展,则UWP应用程序将关闭

边缘扩展本机消息:如果没有响应发送回边缘浏览器/扩展,则UWP应用程序将关闭,uwp,windows-10,desktop-bridge,microsoft-edge-extension,Uwp,Windows 10,Desktop Bridge,Microsoft Edge Extension,来自Edge browser的每个请求都需要发送相应的响应。如果没有,则伴随的UWP(以及相关的Win32应用程序,如果有)将以“SystemPolicy”作为原因退出。 为了说明这个问题,我可以参考示例 // ///从分机接收消息(通过边缘) /// AppServiceRequestReceived上的私有异步无效(AppServiceConnection发送方、AppServiceRequestReceivedEventArgs参数) { AppServiceDeleral Messag

来自Edge browser的每个请求都需要发送相应的响应。如果没有,则伴随的UWP(以及相关的Win32应用程序,如果有)将以“SystemPolicy”作为原因退出。 为了说明这个问题,我可以参考示例

//
///从分机接收消息(通过边缘)
/// 
AppServiceRequestReceived上的私有异步无效(AppServiceConnection发送方、AppServiceRequestReceivedEventArgs参数)
{
AppServiceDeleral MessageDeleral=args.getDeleral();
尝试
{
如果(this.desktopBridgeAppLaunched)
{
this.currentConnectionIndex=Int32.Parse(sender.AppServiceName);
this.desktopBridgeConnection=desktopBridgeConnections[this.currentConnectionIndex];
//向desktopBridge组件发送消息并等待响应
AppServiceResponse desktopBridgeResponse=等待此.desktopBridgeConnection.SendMessageAsync(args.Request.Message);
wait args.Request.SendResponseAsync(desktopBridgeResponse.Message);
}
其他的
{
抛出新异常(“无法启动desktopBridge应用程序!”);
}
}
最后
{
messagedeleral.Complete();
}
}
通过注释掉调用“SendResponseAsync(…)”的行,UWP和Win32应用程序(PasswordInputProtection.exe)正在退出,因为“OnAppServicesCancelled(…)”处理程序是以SystemPolicy原因调用的

我明白,对于这个特殊的例子,不回复是没有意义的。但是我有一些场景,在这些场景中,不需要将响应发送回Edge扩展。相反,我打算使用Win32应用程序中的SendMessageAsync(…)通过UWP应用程序与扩展进行通信


另外,我注意到,我在网上找到的本机消息示例至少会从UWP向扩展发送一条无用的ACK消息。那么,是出于设计需要发送响应,还是我遗漏了什么

Edge团队对此进行了调查,并确认这是他们其中一个组件中的一个缺陷。他们正在为下一次更新进行修复。在修复完成之前,您需要始终发送响应


感谢您报告此问题,并对由此造成的不便表示歉意

我的期望是,在调用messagedeleral.Complete()时自动生成一个空响应,而不必调用SendResponseAsync()。我刚刚在这里试用过,我的机器似乎就是这样工作的。我的测试是一个纯粹的AppService场景(不是边缘扩展),并且是在最新的内部构建(我假设您在16299上),所以这可能是我们两个测试之间的差异。让我跟Edge Extension的人一起看看这里可能缺少什么。谢谢你的回复Stefan。1.是的,我是16299。2.所以你的意思是说你尝试了两个UWP应用程序之间的单向异步通信(都不是EdgeExtension),它们工作得很好??我还没试过。然而,我试图在SendResponseAsync()中发送空响应,令人震惊的是,EdgeBrowser本身一直崩溃。期待您对Edge Extension+UWP的回复
    /// <summary>
    /// Receives message from Extension (via Edge)
    /// </summary>
    private async void OnAppServiceRequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
    {
        AppServiceDeferral messageDeferral = args.GetDeferral();

        try
        {
            if (this.desktopBridgeAppLaunched)
            {
                this.currentConnectionIndex = Int32.Parse(sender.AppServiceName);
                this.desktopBridgeConnection = desktopBridgeConnections[this.currentConnectionIndex];

                // Send message to the desktopBridge component and wait for response
                AppServiceResponse desktopBridgeResponse = await this.desktopBridgeConnection.SendMessageAsync(args.Request.Message);
                await args.Request.SendResponseAsync(desktopBridgeResponse.Message);
            }
            else
            {
                throw new Exception("Failed to launch desktopBridge App!");
            }
        }
        finally
        {
            messageDeferral.Complete();
        }
    }