]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | /* |
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 | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
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 | |
17 | * under the License. | |
18 | */ | |
19 | ||
20 | using System; | |
21 | using Thrift; | |
22 | using Thrift.Protocol; | |
23 | using Thrift.Server; | |
24 | using Thrift.Transport; | |
25 | ||
26 | ||
27 | namespace CSharpTutorial | |
28 | { | |
29 | public class CSharpClient | |
30 | { | |
31 | public static void Main() | |
32 | { | |
33 | try | |
34 | { | |
35 | TTransport transport = new TSocket("localhost", 9090); | |
36 | TProtocol protocol = new TBinaryProtocol(transport); | |
37 | Calculator.Client client = new Calculator.Client(protocol); | |
38 | ||
39 | transport.Open(); | |
40 | try | |
41 | { | |
42 | client.ping(); | |
43 | Console.WriteLine("ping()"); | |
44 | ||
45 | int sum = client.add(1, 1); | |
46 | Console.WriteLine("1+1={0}", sum); | |
47 | ||
48 | Work work = new Work(); | |
49 | ||
50 | work.Op = Operation.DIVIDE; | |
51 | work.Num1 = 1; | |
52 | work.Num2 = 0; | |
53 | try | |
54 | { | |
55 | int quotient = client.calculate(1, work); | |
56 | Console.WriteLine("Whoa we can divide by 0"); | |
57 | } | |
58 | catch (InvalidOperation io) | |
59 | { | |
60 | Console.WriteLine("Invalid operation: " + io.Why); | |
61 | } | |
62 | ||
63 | work.Op = Operation.SUBTRACT; | |
64 | work.Num1 = 15; | |
65 | work.Num2 = 10; | |
66 | try | |
67 | { | |
68 | int diff = client.calculate(1, work); | |
69 | Console.WriteLine("15-10={0}", diff); | |
70 | } | |
71 | catch (InvalidOperation io) | |
72 | { | |
73 | Console.WriteLine("Invalid operation: " + io.Why); | |
74 | } | |
75 | ||
76 | SharedStruct log = client.getStruct(1); | |
77 | Console.WriteLine("Check log: {0}", log.Value); | |
78 | ||
79 | } | |
80 | finally | |
81 | { | |
82 | transport.Close(); | |
83 | } | |
84 | } | |
85 | catch (TApplicationException x) | |
86 | { | |
87 | Console.WriteLine(x.StackTrace); | |
88 | } | |
89 | ||
90 | } | |
91 | } | |
92 | } |