c# - .NET HBase REST API 客户端库 - 从 MVC5 Controller 调用

标签 c# asp.net-mvc azure hadoop hbase

查看 https://azure.microsoft.com/en-us/documentation/articles/hdinsight-hbase-tutorial-get-started/#use-the-net-hbase-rest-api-client-library 上给出的示例代码,

我尝试从 MVC Controller 连接到 HBase,如下所示:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;

using Microsoft.HBase.Client;
using org.apache.hadoop.hbase.rest.protobuf.generated;

namespace MyHBaseTest.Controllers
{
    [RoutePrefix("api/myhbasetestcontroller")]
    public class MyHBaseTestController : ApiController
    {
        HBaseReader hbase = new HBaseReader();

        [HttpGet]
        [Route("")]
        public IHttpActionResult Index()
        {

            string clusterURL = "https://<yourHBaseClusterName>.azurehdinsight.net";
            string hadoopUsername = "<yourHadoopUsername>";
            string hadoopUserPassword = "<yourHadoopUserPassword>";

            // Create a new instance of an HBase client.
            ClusterCredentials creds = new ClusterCredentials(new Uri(clusterURL), hadoopUsername, hadoopUserPassword);
            HBaseClient hbaseClient = new HBaseClient(creds);

            // Retrieve the cluster version
            var version = hbaseClient.GetVersion();
            Console.WriteLine("The HBase cluster version is " + version);

            return Ok();
        }
    }
}

当我尝试在浏览器中以 Debug模式运行时查看 URL/api/myhbasetestcontroller 时,它会永远加载页面,而不会在 Visual Studio 中抛出任何异常或任何内容。我已经等了 15-20 分钟,但没有任何变化。

当我尝试在控制台应用程序中执行相同操作时,它会在几秒钟内获取版本信息:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Microsoft.HBase.Client;
using org.apache.hadoop.hbase.rest.protobuf.generated;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string clusterURL = "https://<yourHBaseClusterName>.azurehdinsight.net";
            string hadoopUsername= "<yourHadoopUsername>";
            string hadoopUserPassword = "<yourHadoopUserPassword>";

            // Create a new instance of an HBase client.
            ClusterCredentials creds = new ClusterCredentials(new Uri(clusterURL), hadoopUsername, hadoopUserPassword);
            HBaseClient hbaseClient = new HBaseClient(creds);

            // Retrieve the cluster version
            var version = hbaseClient.GetVersion();
            Console.WriteLine("The HBase cluster version is " + version);
        }
    }
}

我只是不明白这到底有何不同。

能给点建议吗?

非常感谢。

最佳答案

从今天开始,您需要在后台线程上运行调用。我遇到了同样的问题。我的通话被整合到一个函数中。我在后台线程上运行该函数,一切正常。

        // POST: api/Vizzini
    [ResponseType(typeof(string))]
    public async Task<IHttpActionResult> GetResponse(string tweet)
    {
        string s = await Task.Run(() =>
        {
            return ResponseEngine.GetBestResponse(tweet);
        });
        return Ok(s);
    }

关于c# - .NET HBase REST API 客户端库 - 从 MVC5 Controller 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30971186/

相关文章:

azure - 如何在 Azure DevOps 中的另一个变量中使用一个变量

c# - 是否有更高级的 C# 控制台库?

c# - 快图 : Cycle Detection

移动节点后 C# Treeview 不刷新

azure - 如何在Azure Data Lake存储上预处理和解压缩.gz文件?

django - 有选择地删除上传到 Azure blob 的图像(Django/Python 项目)

c# - 如何在 C# Windows 应用程序中进行身份验证和授权?

javascript - 无法将表单数据发布到 Controller

c# - asp.net mvc Response.Redirect 在 global.asax 中不起作用

javascript - 为什么这些cookie代码在asp.net mvc中不起作用?