When I was learning WCF today with C # rewriting test examples, an error occurred: Unable to connect because the target computer was actively rejecting. Find n Long, online also did not find the actual solution. View Netstat-an Discovery when the self-hosted host is running, there is no port listening for configuration. The beginning is always thought to be a configuration problem. Finally began to doubt the problem of the program.
The final inspection program found that
[HTML]View Plaincopy
- using (ServiceHost host = new ServiceHost (typeof (Artech.WcfServices.Services.CalculatorService)))
- {
- Console.WriteLine ("started!");
- Start Hosting
- Host. Open ();
- }
- Console.readkey ();
It looks like the host is running, but the host has been shut down for a lifetime. Because the console.readky is outside the using, the host is always assumed to be running. actually otherwise
This is then modified to:
[CSharp]View Plaincopy
- using (ServiceHost host = new ServiceHost (typeof (Artech.WcfServices.Services.CalculatorService)))
- {
- Console.WriteLine ("started!");
- //Start hosting
- Host. Open ();
- Console.readkey ();
- }
Everything OK. It took me half an afternoon to find this little problem.
This also shows that learning can not only stay on the surface, for using the usage is actually not mastered. Ashamed!
WCF error: Unable to connect because the target computer is actively rejecting