Using native messaging extension for Edge, is it possible to send more than one response to a single request? Besides other features my extension is intended to support file uploading, but I need to deal with the native message size limitation. Due to this, I would like to send the file data splitted to multiple chunks:
private async void OnAppServiceRequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
{
AppServiceDeferral messageDeferral = args.GetDeferral();
try
{
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);
// Response Message is a ValueSet with all parts of processed file
foreach (KeyValuePair<String, Object> chunk in desktopBridgeResponse.Message)
{
ValueSet vs = new ValueSet();
vs.Add(chunk.Key, chunk.Value);
await args.Request.SendResponseAsync(vs);
}
}
catch(Exception ex)
{
//The InvalidOperationException is thrown after second SendResponseAsync call
Utils.Log(ex.ToString());
}
finally
{
messageDeferral.Complete();
}
}
The javascript part of extension is ready for this, as we use it successfully in Firefox and Chrome - it knows when it receives a single message or a chunk (based on the data header). But the problem is that whenever I call AppServiceRequest.SendResponseAsync()
the port gets closed (automatically?) after the response is sent. It must be closed by some part of the UWP application, because closing the port by JS part is logged, and no such record is present in Edge console. Trying to send another chunk leads to a
System.InvalidOperationException: A method was called at an unexpected time exception
being thrown.
I have come over a similar question here on SO where the response suggests to check work with deferrals, but after a few code revisions it seems right to me (my project is based on a MSFT sample).
I also tried to set "background": { persistent: true }
in manifest.json
, but it seems to have no effect on this.
Is there anything else I have to check/set? Or is this behavior not supported?