8
8
using System . Threading . Tasks ;
9
9
10
10
using Grpc . Core ;
11
+ using Grpc . Net . Client ;
11
12
using Microsoft . Azure . WebJobs . Script . Grpc . Messages ;
12
13
13
14
namespace Microsoft . Azure . Functions . PowerShellWorker . Messaging
@@ -19,15 +20,24 @@ internal class MessagingStream
19
20
20
21
internal MessagingStream ( string host , int port )
21
22
{
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
+
22
31
const int maxMessageLength = int . MaxValue ;
23
32
24
- var channelOptions = new [ ]
33
+ var channelOptions = new GrpcChannelOptions
25
34
{
26
- new ChannelOption ( ChannelOptions . MaxReceiveMessageLength , maxMessageLength ) ,
27
- new ChannelOption ( ChannelOptions . MaxSendMessageLength , maxMessageLength )
35
+ MaxReceiveMessageSize = maxMessageLength ,
36
+ MaxSendMessageSize = maxMessageLength ,
37
+ Credentials = ChannelCredentials . Insecure
28
38
} ;
29
39
30
- Channel channel = new Channel ( host , port , ChannelCredentials . Insecure , channelOptions ) ;
40
+ GrpcChannel channel = GrpcChannel . ForAddress ( grpcUri , channelOptions ) ;
31
41
_call = new FunctionRpc . FunctionRpcClient ( channel ) . EventStream ( ) ;
32
42
}
33
43
0 commit comments