如何将 eos-sharp 与 ASP.NET Core web API 一起使用?
How to use eos-sharp with ASP.NET Core web API?
我正在编写 Web API 以从多索引 table 数据中获取用户数据。下面是我的 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: Exception of type 'EosSharp.Core.Exceptions.ApiErrorException' was thrown.
我在多索引中有用户数据 table users 和 return 来自 API 的所有用户。有人可以帮我解决错误和 return 类型吗?我也不确定 return 类型 IAsyncEnumerable 和 yield return with async.
我用了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;
}
}
我正在编写 Web API 以从多索引 table 数据中获取用户数据。下面是我的 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: Exception of type 'EosSharp.Core.Exceptions.ApiErrorException' was thrown.
我在多索引中有用户数据 table users 和 return 来自 API 的所有用户。有人可以帮我解决错误和 return 类型吗?我也不确定 return 类型 IAsyncEnumerable 和 yield return with async.
我用了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;
}
}