blob: ab9eadafa065f26480e5bf5a0189673925e99589 [file] [log] [blame]
Adam Connelly0c0649d2015-12-26 15:55:05 +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
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 await asyncService.blahBlahAsync();
45 var result = await asyncService.secondtestStringAsync("TestString");
46 if (result != "TestString")
47 {
48 throw new Exception("The wrong result was returned");
49 }
50
51 return RedirectToAction("Index");
52 }
53
54 public ActionResult TestThriftSync()
55 {
56 var baseUri = new Uri(string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority,
57 Url.Content("~")));
58
59 SecondService.ISync service =
60 new SecondService.Client(new TBinaryProtocol(new THttpClient(new Uri(baseUri, "Sync.thrift"))));
61
62 service.blahBlah();
63 var result = service.secondtestString("TestString");
64 if (result != "TestString")
65 {
66 throw new Exception("The wrong result was returned");
67 }
68
69 return RedirectToAction("Index");
70 }
71 }
72}