简体   繁体   English

“无法建立连接,因为目标机器主动拒绝它” Nethereum 异常

[英]“No connection could be made because the target machine actively refused it” Nethereum exception

I am using Nethereum to call a function called owner() in a BSC contract, which should return the contract owner's address, however when I use the CallAsync() method, I get an exception "No connection could be made because the target machine actively refused it"我正在使用 Nethereum 在 BSC 合约中调用一个名为owner()的函数,该函数应该返回合约所有者的地址,但是当我使用CallAsync()方法时,出现异常“无法建立连接,因为目标机器主动拒绝了”

My code (simplified):我的代码(简化):

using (var s = webRequest.GetResponse().GetResponseStream())
{
    using (var sr = new StreamReader(s))
    {
        string contractABIstr = sr.ReadToEnd();
        JObject contractABI = JObject.Parse(contractABIstr);
        string contractResults = (string)contractABI.SelectToken("result");

        var web3 = new Web3();
        var contract = web3.Eth.GetContract(contractResults, address);
        Nethereum.Contracts.Function = contract.GetFunction("owner");

        string owner = "";
        Task<string> task = function.CallAsync<string>();
        owner = await task;
    }
}

When calling the line owner = await task , I get an exception with message "Error occurred when trying to send rpc requests(s)", which has an inner exception with the message "An error occurred while sending the request.", which has its own inner exception with the message "Unable to connect to the remote server", and this one has its own inner exception saying "No connection could be made because the target machine actively refused it [IP address]"当调用行owner = await task ,我收到一个异常消息“尝试发送 rpc 请求时发生错误”,它有一个内部异常消息“发送请求时发生错误。”,它有它自己的内部异常消息“无法连接到远程服务器”,而这个内部异常表示“无法建立连接,因为目标机器主动拒绝了它[IP 地址]”

Does anyone know what I'm doing wrong here?有谁知道我在这里做错了什么? (I've simplified the code above but I do check that the function exists) (我已经简化了上面的代码,但我确实检查了该函数是否存在)

My problem turned out to be that I had initialised the Web3() with no parameters, so it defaults to using localhost as the RPC client.我的问题原来是我初始化了没有参数的 Web3(),所以它默认使用 localhost 作为 RPC 客户端。 I fixed it by initialising it with the RPC client url that I needed, in this case:我通过使用我需要的 RPC 客户端 url 初始化它来修复它,在这种情况下:

string rpcClient = "https://bsc-dataseed.binance.org/";
Web3 web3 = new Web3(rpcClient);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SignalR错误“由于目标机器主动拒绝连接,因此无法建立连接” - SignalR Error “No connection could be made because the target machine actively refused it” 无法建立连接,因为目标计算机主动拒绝了它216.58.212.106:443 - No connection could be made because the target machine actively refused it 216.58.212.106:443 '由于目标机器主动拒绝它,因此无法建立连接 - 'No connection could be made because the target machine actively refused it 由于目标计算机主动拒绝连接,因此无法建立连接-客户端 - No connection could be made because the target machine actively refused it - client side 无法建立连接,因为目标计算机主动拒绝了127.0.0.1:8000 - No connection could be made because the target machine actively refused it 127.0.0.1:8000 由于目标计算机主动拒绝连接,因此无法建立连接-套接字程序 - No connection could be made because the target machine actively refused it - Socket Program 没有连接,因为目标机器主动拒绝它为什么? - No connection could be made because the target machine actively refused it why? “无法建立连接,因为目标计算机主动拒绝了它” - “No connection could be made because the target machine actively refused it” 无法建立连接,因为目标计算机主动拒绝它127.0.0.1:32450 - No connection could be made because the target machine actively refused it 127.0.0.1:32450 无法建立连接,因为目标计算机主动拒绝它127.0.0.1:8082 - No connection could be made because the target machine actively refused it 127.0.0.1:8082
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM