0

我正在编写 Web API 以从多索引表数据中获取用户数据。以下是我的 API 方法:

[HttpGet]
        public async IAsyncEnumerable<GetTableRowsResponse>  GetUsers()
            //public async Task<IHttpActionResult> GetUsers()
        {
            Eos eos = new Eos(new EosConfigurator()
            {
                HttpEndpoint = "http://127.0.0.1:8888/v1/chain", //running nodeos on localhost
                ChainId = "nodeoschainid",
                ExpireSeconds = 60,
                SignProvider = new DefaultSignProvider("MyPK")
            });

            var result = await eos.GetTableRows(new GetTableRowsRequest()
            {
                json = true,
                code = "groupacc",
                scope = "groupacc",
                table = "users"
            });

            yield return result;
        }

这是抛出异常:

ApiErrorException:引发了“EosSharp.Core.Exceptions.ApiErrorException”类型的异常。

我在多索引表用户中有用户数据,并从 API 返回所有用户。任何人都可以帮助我处理错误和返回类型吗?此外,我不确定返回类型IAsyncEnumerable和异步产生返回

4

1 回答 1

0

我用过JsonConvert。完整代码如下:

public async Task<string> GetUsers(string code, string scope, string table)
{
            try
            {
                Eos eos = new Eos(new EosConfigurator()
                {
                   HttpEndpoint = "http://127.0.0.1:8888/v1/chain", 
                   ChainId = "nodeoschainid",
                   ExpireSeconds = 60,
                   SignProvider = new DefaultSignProvider("MyPK")
                });
                GetTableRowsResponse result = await eos.GetTableRows(new GetTableRowsRequest()
                {
                    json = true,
                    code = "groupacc",
                    scope = "groupacc",
                    table = "users"
                });

                string resultJson = JsonConvert.SerializeObject(result.rows);
                return resultJson;

            }
            catch (Exception)
            {
                throw;
            }
  }
于 2020-12-18T10:41:10.250 回答