private static async Task TestAsync(string from, string endpoint, MyService.MyServiceClient client) { try { Log($"Sending Ping to {endpoint}"); var deadline = DateTime.UtcNow.AddMilliseconds(500); await client.PingAsync(new PingRequest { Name = from }, deadline : deadline); } catch (Exception ex) { Log($"Failed to Ping {endpoint}: {ex.Message}"); } try { Log($"Sending Echo to {endpoint}"); var deadline = DateTime.UtcNow.AddMilliseconds(500); var resp = await client.EchoAsync(new EchoRequest { Message = from }, deadline : deadline); Log($"Echo response from {endpoint}: {resp.Message}"); } catch (Exception ex) { Log($"Failed to Echo {endpoint}: {ex.Message}"); } }
static void Main(string[] args) { var channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure); var client = new MyService.MyServiceClient(channel); RunClient(client).Wait(); channel.ShutdownAsync().Wait(); }
static async Task RunClient(MyService.MyServiceClient client) { var requests = new MyRequest[] { new MyRequest() { Message = "Request 1" }, new MyRequest() { Message = "Request 2" } }; foreach (var request in requests) { var reply = await client.SendRequestAsync(request); Console.WriteLine($"Client received response: '{reply.Message}', '{reply.Foo}'"); } }
static void TestService() { DownloadFromMyMac ("config.xml"); DownloadFromMyMac ("config.xsd"); C.ConfigurationHost.Install ("config.xml", "config.xsd"); WebRequest.DefaultWebProxy = new WebProxy ("http://192.168.16.104:3128"); var client = new MyService.MyServiceClient (); var hello = client.Hello (); Console.WriteLine ("Got response from service: {0}", hello); }
async static Task Run() { var requests = new DoMessage[] { new DoMessage() { In = "First" }, new DoMessage() { In = "Second" }, new DoMessage() { In = "Third" }, new DoMessage() { In = "4" }, new DoMessage() { In = "5" }, new DoMessage() { In = "6" }, new DoMessage() { In = "7" }, new DoMessage() { In = "8" }, new DoMessage() { In = "9" }, new DoMessage() { In = "10" }, new DoMessage() { In = "11" } }; Channel channel = new Channel("localhost", 50051, ChannelCredentials.Insecure); var client = new MyService.MyServiceClient(channel); Console.WriteLine("Starting..."); var options = new CallOptions().WithDeadline(DateTime.UtcNow.AddSeconds(15)).WithWaitForReady(true); using (var call = client.Do(options)) { var responseReaderTask = Task.Run(async() => { Console.WriteLine("Receiving..."); while (await call.ResponseStream.MoveNext()) { Console.WriteLine("Waiting..."); var note = call.ResponseStream.Current; Console.WriteLine("Received " + note.In); } Console.WriteLine("End Received"); }).ContinueWith(task => { if (task.IsFaulted) { Console.WriteLine("SERVER: " + task.Exception.ToString()); foreach (var item in task.Exception.InnerExceptions) { Console.WriteLine("--- INNER SERVER"); Console.WriteLine(item.ToString()); } } }); Console.WriteLine("Sending"); foreach (DoMessage request in requests) { Console.WriteLine("Sending " + request.In); await call.RequestStream.WriteAsync(request); Console.WriteLine("Sent " + request.In); } await call.RequestStream.CompleteAsync(); Console.WriteLine("End Sending"); await responseReaderTask; } channel.ShutdownAsync().Wait(); Console.WriteLine("Hello World!"); }
static void TestService(string xmlFilename, string xsdFilename) { ConfigurationHost.Install (xmlFilename, xsdFilename); var client = new MyService.MyServiceClient (); var hello = client.Hello (); Console.WriteLine ("Got response from service: {0}", hello); }
static void TestClient() { var netTcp = new NetTcpBinding (SecurityMode.TransportWithMessageCredential, false); netTcp.TransferMode = TransferMode.Streamed; netTcp.Security.Transport.ClientCredentialType = TcpClientCredentialType.None; // var binding = new CustomBinding (); // binding.Elements.Add (new TextMessageEncodingBindingElement ()); // binding.Elements.Add (new TcpTransportBindingElement ()); var address = new EndpointAddress ("net.tcp://provcon-faust:8888/MyService/"); var client = new MyService.MyServiceClient (netTcp, address); var serviceAuth = client.ClientCredentials.ServiceCertificate.Authentication; serviceAuth.CertificateValidationMode = X509CertificateValidationMode.PeerOrChainTrust; serviceAuth.TrustedStoreLocation = StoreLocation.LocalMachine; var hello = client.Hello (); Console.WriteLine ("Got response from service: {0}", hello); }