blob: 113a47223450323d5e2260aa3b0397a5e006f308 [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +00001/*
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
David Reiss06a93122009-03-30 21:22:52 +000020using System;
21using Thrift;
22using Thrift.Protocol;
23using Thrift.Server;
24using Thrift.Transport;
25
26
27namespace 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();
David Reiss06a93122009-03-30 21:22:52 +000040 try
41 {
Jens Geyer102bca42013-06-25 22:21:29 +020042 client.ping();
43 Console.WriteLine("ping()");
David Reiss06a93122009-03-30 21:22:52 +000044
Jens Geyer102bca42013-06-25 22:21:29 +020045 int sum = client.add(1, 1);
46 Console.WriteLine("1+1={0}", sum);
David Reiss06a93122009-03-30 21:22:52 +000047
Jens Geyer102bca42013-06-25 22:21:29 +020048 Work work = new Work();
David Reiss06a93122009-03-30 21:22:52 +000049
Jens Geyer102bca42013-06-25 22:21:29 +020050 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 }
David Reiss06a93122009-03-30 21:22:52 +000084 }
85 catch (TApplicationException x)
86 {
87 Console.WriteLine(x.StackTrace);
88 }
89
90 }
91 }
92}