blob: c9a1ec43fdd6bc3d048801ccc8e30f5f443416bc [file] [log] [blame]
Jens Geyerb89316d2020-02-28 19:22:34 +01001/**
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
20using System;
21using System.Threading.Tasks;
22using System.Web.Mvc;
23using Thrift.Protocol;
24using Thrift.Test;
25using Thrift.Transport;
26
27namespace ThriftMVCTest.Controllers
28{
29 public class HomeController : Controller
30 {
31 public ActionResult Index()
32 {
33 return View();
34 }
35
36 public async Task<ActionResult> TestThriftAsync()
37 {
38 var baseUri = new Uri(string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority,
39 Url.Content("~")));
40
41 SecondService.IAsync asyncService =
42 new SecondService.Client(new TBinaryProtocol(new THttpClient(new Uri(baseUri, "Async.thrift"))));
43
44 var result = await asyncService.secondtestStringAsync("TestString");
45 if (result != "testString(\"TestString\")")
46 {
47 throw new Exception("The wrong result was returned");
48 }
49
50 return RedirectToAction("Index");
51 }
52
53 public ActionResult TestThriftSync()
54 {
55 var baseUri = new Uri(string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority,
56 Url.Content("~")));
57
58 SecondService.ISync service =
59 new SecondService.Client(new TBinaryProtocol(new THttpClient(new Uri(baseUri, "Sync.thrift"))));
60
61 var result = service.secondtestString("TestString");
62 if (result != "testString(\"TestString\")")
63 {
64 throw new Exception("The wrong result was returned");
65 }
66
67 return RedirectToAction("Index");
68 }
69 }
70}