From f9b38d31d63086766de1180d023db622fe50df27 Mon Sep 17 00:00:00 2001 From: Michael Peng Date: Tue, 22 Feb 2022 12:14:14 -0800 Subject: [PATCH 1/2] Switch from Grpc.Core to Grpc.Net.Client (#758) * Upgraded protobuf versions and removed Grpc.Core dependency * Updated channel and option types used * Change channel credentials * Added http prefix to url * Add valid URL check and explicitly include credentials --- src/Messaging/MessagingStream.cs | 18 ++++++++++++++---- ...oft.Azure.Functions.PowerShellWorker.csproj | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Messaging/MessagingStream.cs b/src/Messaging/MessagingStream.cs index 82f1e108..596c7737 100644 --- a/src/Messaging/MessagingStream.cs +++ b/src/Messaging/MessagingStream.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Grpc.Core; +using Grpc.Net.Client; using Microsoft.Azure.WebJobs.Script.Grpc.Messages; namespace Microsoft.Azure.Functions.PowerShellWorker.Messaging @@ -19,15 +20,24 @@ internal class MessagingStream internal MessagingStream(string host, int port) { + // To call unsecured gRPC services, ensure the address starts with 'http' as opposed to 'https'. + // For more detail, see https://docs.microsoft.com/en-us/aspnet/core/grpc/client?view=aspnetcore-6.0 + string uriString = $"http://{host}:{port}"; + if (!Uri.TryCreate(uriString, UriKind.Absolute, out Uri grpcUri)) + { + throw new InvalidOperationException($"The gRPC channel URI '{uriString}' could not be parsed."); + } + const int maxMessageLength = int.MaxValue; - var channelOptions = new [] + var channelOptions = new GrpcChannelOptions { - new ChannelOption(ChannelOptions.MaxReceiveMessageLength, maxMessageLength), - new ChannelOption(ChannelOptions.MaxSendMessageLength, maxMessageLength) + MaxReceiveMessageSize = maxMessageLength, + MaxSendMessageSize = maxMessageLength, + Credentials = ChannelCredentials.Insecure }; - Channel channel = new Channel(host, port, ChannelCredentials.Insecure, channelOptions); + GrpcChannel channel = GrpcChannel.ForAddress(grpcUri, channelOptions); _call = new FunctionRpc.FunctionRpcClient(channel).EventStream(); } diff --git a/src/Microsoft.Azure.Functions.PowerShellWorker.csproj b/src/Microsoft.Azure.Functions.PowerShellWorker.csproj index d427a8bb..85d5f067 100644 --- a/src/Microsoft.Azure.Functions.PowerShellWorker.csproj +++ b/src/Microsoft.Azure.Functions.PowerShellWorker.csproj @@ -20,7 +20,7 @@ Licensed under the MIT license. See LICENSE file in the project root for full li - + From 30bc44555ae6cf3bb06f2af57781dfa5046141c3 Mon Sep 17 00:00:00 2001 From: Michael Peng Date: Mon, 13 Jun 2022 13:28:48 -0700 Subject: [PATCH 2/2] Added package reference to Grpc.Net.Client --- src/Microsoft.Azure.Functions.PowerShellWorker.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.Azure.Functions.PowerShellWorker.csproj b/src/Microsoft.Azure.Functions.PowerShellWorker.csproj index 85d5f067..49eae5bf 100644 --- a/src/Microsoft.Azure.Functions.PowerShellWorker.csproj +++ b/src/Microsoft.Azure.Functions.PowerShellWorker.csproj @@ -20,7 +20,7 @@ Licensed under the MIT license. See LICENSE file in the project root for full li - +