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
21 using System.Threading.Tasks;
23 using Thrift.Protocol;
25 using Thrift.Transport;
27 namespace ThriftMVCTest.Controllers
29 public class HomeController : Controller
31 public ActionResult Index()
36 public async Task<ActionResult> TestThriftAsync()
38 var baseUri = new Uri(string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority,
41 SecondService.IAsync asyncService =
42 new SecondService.Client(new TBinaryProtocol(new THttpClient(new Uri(baseUri, "Async.thrift"))));
44 var result = await asyncService.secondtestStringAsync("TestString");
45 if (result != "testString(\"TestString\")")
47 throw new Exception("The wrong result was returned");
50 return RedirectToAction("Index");
53 public ActionResult TestThriftSync()
55 var baseUri = new Uri(string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority,
58 SecondService.ISync service =
59 new SecondService.Client(new TBinaryProtocol(new THttpClient(new Uri(baseUri, "Sync.thrift"))));
61 var result = service.secondtestString("TestString");
62 if (result != "testString(\"TestString\")")
64 throw new Exception("The wrong result was returned");
67 return RedirectToAction("Index");