No Connection Could Be Made Because the Target MAChine Actively Refused It 127.0.0.1:3446

No connection could be made because the target machine actively refused it 127.0.0.1:3446

"Actively refused it" means that the host sent a reset instead of an ack when you tried to connect. It is therefore not a problem in your code. Either there is a firewall blocking the connection or the process that is hosting the service is not listening on that port. This may be because it is not running at all or because it is listening on a different port.

Once you start the process hosting your service, try netstat -anb (requires admin privileges) to verify that it is running and listening on the expected port.

update: On Linux you may need to do netstat -anp instead.

No connection could be made because the target machine actively refused it [http://127.0.0.1:8000/auth/login]

Try changing the endpoint (base) address to include also the port to http://127.0.0.1:8000:

Dictionary<string, string> postUrl = new Dictionary<string, string>()
{
{ "endpoint", "http://127.0.0.1:8000"},
{ "resource", "auth/login"},
{ "paramaters", ""},
{ "key", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRlY2hpZUBlbWFpbC5jb20iLCJwYXNzd29yZCI6InRlY2hpZSIsImlhdCI6MTYxMDYzNjYzNywiZXhwIjoxNjEwNjQwMjM3fQ.CW6adTp9PNT3oTiQVKSy3HHYZMimUM12V5aWUiyDPoc"}
};

No connection could be made because the target machine actively refused it'

I was starting to forget this post but I finally found the problem that was messing things up and it has nothing to do with programmation.

I was doing the calls while the device was connected to the computer via the 'Windows Mobile Device Center' allowing to access the device from Windows.
While connected, the host provided is ignored and all calls on the specified port are handled by the connected computer.
Disconnecting the device allows to communicate properly...

No connection could be made because the target machine actively refused it 127.0.0.1:port with subdomain

The netstat output shows that only IP v6 addresses are used, which is not quite typical, but should be OK if for some reason IP v4 is not used on the machine. Then you cannot expect IP v4 packets (to 127.0.0.1) be processed by the server.

One quick solution is to set in hosts file a record of [::1] instead of 127.0.0.1.

No connection could be made because the target machine actively refused it 127.0.0.1:63591

Are you sure that your database instance are running? Check it in configuration manager of your SQL Server and also the default port.

Csharp Sample Image 7

Csharp Sample Image 10

After, compare with your port number in connection string of your web config.

<connectionStrings>
<clear/>
<add name="xxxxx" connectionString="metadata=res://*/xxxx.csdl|res://*/xxx.ssdl|res://*/xxx.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\xxxxxx;Initial Catalog=xx;Persist Security Info=True;User ID=yyy;Password=yyyy;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient"/></connectionStrings>

So, after I debugged your code I found the problems in your solution.

1-**The first cause of this problem is a **"Self referencing loop detected for property", because your are trying to serialize the Entity Framework object directly with public IQueryable GetFoods(). Since Food have MealFood and the MealFood have a reference back to Food, it cannot be serialized.

The solution is to add in your Global.asax this code GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;

your method will be like this :

protected void Application_Start(){ GlobalConfiguration.Configure(WebApiConfig.Register); GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; }

Here we need to define global setting for JSON.Net serializer to ignore circular references.

2-**The second problem is **"The entity or complex type 'Model' cannot be constructed in a LINQ to Entities query".

To resolve this you can create a Pseudo Class of your Food Class like this
one:

public class PseudoFood
{
public int FoodID { get; set; }
public string FoodName { get; set; }
public int Calories { get; set; }
public string Notes { get; set; }
}

after it's possible to query your DB with this method.

public IQueryable<PseudoFood> GetFoods()
{ return (from a in db.Foods orderby a.FoodName descending select new PseudoFood()
{ FoodName = a.FoodName, FoodID = a.FoodID,
Calories = a.Calories, Notes = a.Notes } ).AsQueryable(); }

returning PseudoFood "IQueryable" and finally retrieve your record.

Csharp Sample Image 9

No connection could be made because the target machine actively refused it 127.0.0.1

After six days I find the answer which make me crazy! The answer is disable proxy at web.config file:

<system.net>
<defaultProxy>
<proxy usesystemdefault="False"/>
</defaultProxy>
</system.net>


Related Topics



Leave a reply



Submit