2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
22 using Thrift.Protocol;
24 using Thrift.Transport;
27 namespace CSharpTutorial
29 public class CSharpClient
31 public static void Main()
35 TTransport transport = new TSocket("localhost", 9090);
36 TProtocol protocol = new TBinaryProtocol(transport);
37 Calculator.Client client = new Calculator.Client(protocol);
43 Console.WriteLine("ping()");
45 int sum = client.add(1, 1);
46 Console.WriteLine("1+1={0}", sum);
48 Work work = new Work();
50 work.Op = Operation.DIVIDE;
55 int quotient = client.calculate(1, work);
56 Console.WriteLine("Whoa we can divide by 0");
58 catch (InvalidOperation io)
60 Console.WriteLine("Invalid operation: " + io.Why);
63 work.Op = Operation.SUBTRACT;
68 int diff = client.calculate(1, work);
69 Console.WriteLine("15-10={0}", diff);
71 catch (InvalidOperation io)
73 Console.WriteLine("Invalid operation: " + io.Why);
76 SharedStruct log = client.getStruct(1);
77 Console.WriteLine("Check log: {0}", log.Value);
85 catch (TApplicationException x)
87 Console.WriteLine(x.StackTrace);