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 aed806b2..31099354 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 - +