public async Task ProcessRequestAsync(HttpContext context, CancellationToken cancellationToken) { var transport = new TStreamTransport(context.Request.Body, context.Response.Body, Configuration); try { var intrans = (InputTransportFactory != null) ? InputTransportFactory.GetTransport(transport) : transport; var outtrans = (OutputTransportFactory != null) ? OutputTransportFactory.GetTransport(transport) : transport; var input = InputProtocolFactory.GetProtocol(intrans); var output = OutputProtocolFactory.GetProtocol(outtrans); while (await Processor.ProcessAsync(input, output, cancellationToken)) { if (!context.Response.HasStarted) // oneway method called { await context.Response.Body.FlushAsync(cancellationToken); } } } catch (TTransportException) { if (!context.Response.HasStarted) // if something goes bust, let the client know { context.Response.StatusCode = 500; } } finally { transport.Close(); } }
public async Task ProcessRequestAsync(HttpContext context, CancellationToken cancellationToken) { var transport = new TStreamTransport(context.Request.Body, context.Response.Body); try { var intrans = (InputTransportFactory != null) ? InputTransportFactory.GetTransport(transport) : transport; var outtrans = (OutputTransportFactory != null) ? OutputTransportFactory.GetTransport(transport) : transport; var input = InputProtocolFactory.GetProtocol(intrans); var output = OutputProtocolFactory.GetProtocol(outtrans); while (await Processor.ProcessAsync(input, output, cancellationToken)) { } } catch (TTransportException) { // Client died, just move on if (!context.Response.HasStarted) { context.Response.StatusCode = 500; } } finally { transport.Close(); } }
public async Task ProcessRequestAsync(HttpContext context, CancellationToken cancellationToken) { var transport = new TStreamTransport(context.Request.Body, context.Response.Body); try { var input = InputProtocolFactory.GetProtocol(transport); var output = OutputProtocolFactory.GetProtocol(transport); while (await Processor.ProcessAsync(input, output, cancellationToken)) { } } catch (TTransportException) { // Client died, just move on } finally { transport.Close(); } }
static void Main(string[] args) { if (args.Length < 4) { Console.WriteLine("server [ns] [hc] [keyname] [key]"); return; } var ns = args[0]; var hc = args[1]; var keyname = args[2]; var key = args[3]; var tokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(keyname, key); var sendAddress = new Uri($"sb://{ns}/{hc}"); var relayClient = new HybridConnectionClient(sendAddress, tokenProvider); try { var relayConnection = relayClient.CreateConnectionAsync().GetAwaiter().GetResult(); TTransport transport = new TStreamTransport(relayConnection, relayConnection); TProtocol protocol = new TBinaryProtocol(transport); Calculator.Client client = new Calculator.Client(protocol); transport.Open(); try { client.ping(); Console.WriteLine("ping()"); int sum = client.add(1, 1); Console.WriteLine("1+1={0}", sum); Work work = new Work(); work.Op = Operation.DIVIDE; work.Num1 = 1; work.Num2 = 0; try { int quotient = client.calculate(1, work); Console.WriteLine("Whoa we can divide by 0"); } catch (InvalidOperation io) { Console.WriteLine("Invalid operation: " + io.Why); } work.Op = Operation.SUBTRACT; work.Num1 = 15; work.Num2 = 10; try { int diff = client.calculate(1, work); Console.WriteLine("15-10={0}", diff); } catch (InvalidOperation io) { Console.WriteLine("Invalid operation: " + io.Why); } SharedStruct log = client.getStruct(1); Console.WriteLine("Check log: {0}", log.Value); } finally { transport.Close(); } } catch (TApplicationException x) { Console.WriteLine(x.StackTrace); } }
public async Task Run(string sendAddress, string sendToken) { try { var relayClient = new RelayClient(sendAddress, TokenProvider.CreateSharedAccessSignatureTokenProvider(sendToken)); var relayConnection = relayClient.Connect(); TTransport transport = new TStreamTransport(relayConnection, relayConnection); TProtocol protocol = new TBinaryProtocol(transport); Calculator.Client client = new Calculator.Client(protocol); transport.Open(); try { client.ping(); Console.WriteLine("ping()"); int sum = client.add(1, 1); Console.WriteLine("1+1={0}", sum); Work work = new Work(); work.Op = Operation.DIVIDE; work.Num1 = 1; work.Num2 = 0; try { int quotient = client.calculate(1, work); Console.WriteLine("Whoa we can divide by 0"); } catch (InvalidOperation io) { Console.WriteLine("Invalid operation: " + io.Why); } work.Op = Operation.SUBTRACT; work.Num1 = 15; work.Num2 = 10; try { int diff = client.calculate(1, work); Console.WriteLine("15-10={0}", diff); } catch (InvalidOperation io) { Console.WriteLine("Invalid operation: " + io.Why); } SharedStruct log = client.getStruct(1); Console.WriteLine("Check log: {0}", log.Value); } finally { transport.Close(); } } catch (TApplicationException x) { Console.WriteLine(x.StackTrace); } }