static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); KeyValueConfigBase keyValue = new StringValueConfig() { Name = "a", Value = "1" }; XmlSerializer s = new XmlSerializer(typeof(KeyValueConfigBase)); using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { s.Serialize(ms, keyValue); System.Diagnostics.Debug.WriteLine(System.Text.Encoding.Default.GetString(ms.ToArray())); } // Load the config from the file. RpcConfigurationConfig config = LoadConfig(@".\GrpcClient.config"); // Create the context. using (RpcConfigurationContext context = new RpcConfigurationContext(config, true)) { Application.Run(new Form1(context)); } }
/// <summary> /// Create a Interceptor. /// </summary> /// <param name="context">The context.</param> /// <exception cref="RpcConfigurationException"> /// The specified name is not found. /// </exception> /// <returns></returns> public override Interceptor CreateInterceptor(RpcConfigurationContext context) { if (context.TryGetInterceptor(ReferencingName, out Interceptor interceptor)) { return(interceptor); } throw new RpcConfigurationException(string.Format("The specified name is not found. The name is '{0}'", ReferencingName)); }
/// <summary> /// Create a <see cref="ServerCredentials"/>. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public override ServerCredentials CreateServerCredentials(RpcConfigurationContext context) { string root = context.GetRootCertificates(RootCertificates); if (string.IsNullOrEmpty(root)) { return(new SslServerCredentials(CreateKeyCertificatePairs(Certificates, context))); } else { return(new SslServerCredentials(CreateKeyCertificatePairs(Certificates, context), root, RequestType)); } }
/// <summary> /// Create a <see cref="ChannelCredentials"/>. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public override ChannelCredentials CreateChannelCredentials(RpcConfigurationContext context) { string root = context.GetRootCertificates(RootCertificates); if (Certificates == null || Certificates.Length == 0) { return(new SslCredentials(root)); } else { return(new SslCredentials(root, Certificates[0].CreateKeyCertificatePair(context))); } }
/// <summary> /// Create a interceptor. /// </summary> /// <param name="context">The context.</param> /// <exception cref="RpcConfigurationException"> /// Could not get the type information. /// </exception> /// <exception cref="RpcConfigurationException"> /// Could not get the method information. /// </exception> /// <exception cref="RpcConfigurationException"> /// The method threw an exception. /// </exception> /// <returns></returns> public override Interceptor CreateInterceptor(RpcConfigurationContext context) { Type type = Type.GetType(TypeName); if (type == null) { throw new RpcConfigurationException(string.Format("Could not get the type information. TypeName is '{0}'.", TypeName)); } if (string.IsNullOrEmpty(MethodName)) { ConstructorInfo ctor = type.GetTypeInfo().GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { }, null); if (type == null) { throw new RpcConfigurationException(string.Format("Could not get the constructor information. TypeName is '{0}'.", TypeName)); } try { return((Interceptor)ctor.Invoke(new object[] { })); } catch (Exception ex) { throw new RpcConfigurationException(string.Format("The constructor threw an exception. TypeName is '{0}'. {1}", TypeName, ex.Message), ex); } } else { MethodInfo method = type.GetTypeInfo().GetMethod(MethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static, null, new Type[] { typeof(CustomInterceptorConfig) }, null); if (method == null) { throw new RpcConfigurationException(string.Format("Could not get the method information. MethodName is '{0}.{1}'.", type.Name, MethodName)); } try { return((Interceptor)method.Invoke(null, new object[] { this })); } catch (Exception ex) { throw new RpcConfigurationException(string.Format("The method threw an exception. MethodName is '{0}.{1}'. {2}", type.Name, MethodName, ex.Message), ex); } } }
/// <summary> /// /// </summary> /// <param name="args"></param> static void Main(string[] args) { // Load the config from the file. RpcConfigurationConfig config = LoadConfig(@".\GrpcServer.config"); // Create the context. using (RpcConfigurationContext context = new RpcConfigurationContext(config, true)) { Server server = new Server(); server.Services.Add(context.Intercept(ExampleService.BindService(new ExampleServiceImpl()), "example1")); server.Ports.Add(context.GetServerPort("channel1")); server.Start(); Console.WriteLine("The server has started."); Console.WriteLine("If you press any key, this application will terminate."); Console.ReadLine(); } Console.WriteLine("The server has shutdown."); System.Threading.Thread.Sleep(1000); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public override Interceptor CreateInterceptor(RpcConfigurationContext context) { return(new ExampleInterceptor(InterceptorName)); }
/// <summary> /// Create <see cref="KeyCertificatePair"/>. /// </summary> /// <param name="configs"></param> /// <param name="context">The context.</param> /// <returns></returns> private IEnumerable <KeyCertificatePair> CreateKeyCertificatePairs(IEnumerable <RpcKeyCertificatePairConfig> configs, RpcConfigurationContext context) { if (configs == null) { yield break; } foreach (RpcKeyCertificatePairConfig config in configs) { yield return(config.CreateKeyCertificatePair(context)); } }
/// <summary> /// Create a <see cref="ServerCredentials"/>. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public override ServerCredentials CreateServerCredentials(RpcConfigurationContext context) { return(ServerCredentials.Insecure); }
/// <summary> /// Create a <see cref="ChannelCredentials"/>. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public override ChannelCredentials CreateChannelCredentials(RpcConfigurationContext context) { return(ChannelCredentials.Insecure); }
/// <summary> /// Create a CallInvoker. /// </summary> /// <param name="channel">The channel.</param> /// <param name="context">The context.</param> /// <returns></returns> public override CallInvoker CreateRootCallInvoker(Channel channel, RpcConfigurationContext context) { return(new DefaultCallInvoker(channel)); }
/// <summary> /// /// </summary> /// <param name="rpcContext"></param> internal Form1(RpcConfigurationContext rpcContext) { InitializeComponent(); m_RpcContext = rpcContext; }