Click here to Skip to main content
15,034,432 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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"

My code (simplified):
C#
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]"

Does anyone know what I'm doing wrong here? (I've simplified the code above but I do check that the function exists)

What I have tried:

Changing configuration from 127.0.0.1, but not sure how to do this as there is no web.config file.
Posted
Updated 27-Jun-21 22:26pm

1 solution

"No connection could be made because the target machine actively refused it" usually means there is a firewall blocking the connection between the two computers.

Assuming you're using the correct IP address and port, that's not something you can fix in your code; you need to get your network admin to check the firewall configuration to make sure you are allowed to connect.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900