Azure-Samples / signalr-service-quickstart-serverless-chat

Serverless chat quickstart samples for Azure SignalR
MIT License
75 stars 62 forks source link

Error getting value from 'ReadTimeout' #14

Open afca-paul opened 5 years ago

afca-paul commented 5 years ago

If I execute the csharp code (/src/chat/csharp) Function "messages" on Azure Function Runtime Version: 2.0.12742.0 I get the following exception:

System.Private.CoreLib: Exception while executing function: messages. Newtonsoft.Json: Error getting value from 'ReadTimeout' on 'Microsoft.AspNetCore.WebUtilities.FileBufferingReadStream'. System.Private.CoreLib: Timeouts are not supported on this stream.

instantgis commented 4 years ago

I am getting the same error above. With my own variant of the back end parts i.e. my own Azure function. And the UWP client (adapted) from here. Pity - I'd really like to use this tech stack i.e. Azure SignalR + Azure Functions + Xamarin client. This is a show stopper.

afca-paul commented 4 years ago

I did find a workaround by doing the serialization upfront and use a json-string as message:

string json = JsonConvert.SerializeObject(statusUpdate, Formatting.Indented);
await signalRMessages.AddAsync(
           new SignalRMessage
           {
                  Target = "updateStatus",
                  Arguments = new[] { json }
            });

I hope this helps.

jhofer commented 4 years ago

Here is my approach

[FunctionName("SendMessage")]
        public static async Task SendMessage(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest req,
            [SignalR(HubName = "chat")] IAsyncCollector<SignalRMessage> signalRMessages)
        {
            var content = await new StreamReader(req.Body).ReadToEndAsync();
            await signalRMessages.AddAsync(
                new SignalRMessage
                {
                    Target = "newMessage",
                    Arguments = new[] { content }
                });

        }
ghost commented 4 years ago

Is this an actual issue or the workaround that @afca-paul and @jhofer provided is what we are supposed to do (permanent solution)?

By the way @jhofer your solution worked perfectly for me, thanks!