88using System . Threading . Tasks ;
99
1010using Grpc . Core ;
11+ using Grpc . Net . Client ;
1112using Microsoft . Azure . WebJobs . Script . Grpc . Messages ;
1213
1314namespace Microsoft . Azure . Functions . PowerShellWorker . Messaging
@@ -19,15 +20,24 @@ internal class MessagingStream
1920
2021 internal MessagingStream ( string host , int port )
2122 {
23+ // To call unsecured gRPC services, ensure the address starts with 'http' as opposed to 'https'.
24+ // For more detail, see https://docs.microsoft.com/en-us/aspnet/core/grpc/client?view=aspnetcore-6.0
25+ string uriString = $ "http://{ host } :{ port } ";
26+ if ( ! Uri . TryCreate ( uriString , UriKind . Absolute , out Uri grpcUri ) )
27+ {
28+ throw new InvalidOperationException ( $ "The gRPC channel URI '{ uriString } ' could not be parsed.") ;
29+ }
30+
2231 const int maxMessageLength = int . MaxValue ;
2332
24- var channelOptions = new [ ]
33+ var channelOptions = new GrpcChannelOptions
2534 {
26- new ChannelOption ( ChannelOptions . MaxReceiveMessageLength , maxMessageLength ) ,
27- new ChannelOption ( ChannelOptions . MaxSendMessageLength , maxMessageLength )
35+ MaxReceiveMessageSize = maxMessageLength ,
36+ MaxSendMessageSize = maxMessageLength ,
37+ Credentials = ChannelCredentials . Insecure
2838 } ;
2939
30- Channel channel = new Channel ( host , port , ChannelCredentials . Insecure , channelOptions ) ;
40+ GrpcChannel channel = GrpcChannel . ForAddress ( grpcUri , channelOptions ) ;
3141 _call = new FunctionRpc . FunctionRpcClient ( channel ) . EventStream ( ) ;
3242 }
3343
0 commit comments