The underlying connection was closed: The connection was closed unexpectedly.

+1 vote

I have a 2-node setup running.  I'm able to issue commands successful from the command line.  However, I can't get the same commands to work via C# code.

I'm getting the following error when calling any method:
 "The underlying connection was closed: The connection was closed unexpectedly."

I'm using the following C# code

string method = "getinfo";
string chainName = "chain1";
string chainKey = null;
int id = 0;
string serviceUrl = http://192.168.133.185:4265/;
string Username = "multichainrpc";
string Password = "HFfnnSbMqSWtF7gb5wZUJZYwGcQ3p4BqkD72s2AYAB2q";

var ps = new JsonRpcRequest()
{
Method = method,
Params = args,
ChainName = chainName,
ChainKey = chainKey,
Id = id
};

var jsonOut = JsonConvert.SerializeObject(ps.Values);
var url = serviceUrl;
var request = WebRequest.CreateHttp(url);
request.Credentials = new NetworkCredential(Username, Password);
request.Method = "POST";
var bs = Encoding.UTF8.GetBytes(jsonOut);

WebResponse response = request.GetResponse();

asked Jan 12, 2018 by Paul

1 Answer

0 votes
Please check you are using the right port - it's different for RPC API commands and the peer-to-peer protocol. The port in the node address reported on the command line is not the right one.
answered Jan 12, 2018 by MultiChain
...