1

I have two self-host .Net application using System.Web.Http.SelfHost targeting .Net framework 4.0, both application commnunicate over https.

The first application is using port: 3287 and the second application is using port: 3286

when I am making a call from the first application to second application using HttpWebRequest class I am getting this exception

System.Net.WebException: Unable to connect to the remote server ---> 
System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:49543
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()

Here is my c# code

HttpWebRequest request = WebRequest.Create("https://localhost.company.com:3286/"+ EndPoint) as HttpWebRequest;
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => 
{
    return true;
};
request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = data.Length;
request.AllowAutoRedirect = false;
request.Expect = "application/json";
request.GetRequestStream().Write(data, 0, data.Length);
HttpWebResponse httpResponse = request.GetResponse() as HttpWebResponse;
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
    string s = streamReader.ReadToEnd();
    return s;
}

as i am calling port 3286 but in exception log port number is changed to 49543.

if I call my application through postman I'm able to get the response from it.

certificate localhost.company.com maps to 127.0.0.1 and I have mapped in host file also.

Prashanth
  • 507
  • 5
  • 25
  • Are you sure your url is http instead of https? – MBB Sep 08 '18 at 13:09
  • [@Mahesh B](https://stackoverflow.com/users/10260399/mahesh-b) i have updated question – Prashanth Sep 10 '18 at 03:11
  • Correct me if I am wrong, You mentioned "both application communicate over http" but the URL is https -https://localhost.company.com:3286/ . Can you also please check whats are the binding details for both of these? – MBB Sep 10 '18 at 12:16

0 Answers0