using System; | |
using Thrift; | |
using Thrift.Protocol; | |
using Thrift.Server; | |
using Thrift.Transport; | |
namespace CSharpTutorial | |
{ | |
public class CSharpClient | |
{ | |
public static void Main() | |
{ | |
try | |
{ | |
TTransport transport = new TSocket("localhost", 9090); | |
TProtocol protocol = new TBinaryProtocol(transport); | |
Calculator.Client client = new Calculator.Client(protocol); | |
transport.Open(); | |
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); | |
transport.Close(); | |
} | |
catch (TApplicationException x) | |
{ | |
Console.WriteLine(x.StackTrace); | |
} | |
} | |
} | |
} |