WCF error: Unable to connect because the target computer is actively rejecting

Source: Internet
Author: User
Tags hosting

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
  1. using (ServiceHost host = new ServiceHost (typeof (Artech.WcfServices.Services.CalculatorService)))
  2. {
  3. Console.WriteLine ("started!");
  4. Start Hosting
  5. Host. Open ();
  6. }
  7. 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
  1. using (ServiceHost host = new ServiceHost (typeof (Artech.WcfServices.Services.CalculatorService)))
  2. {
  3. Console.WriteLine ("started!");
  4. //Start hosting
  5. Host. Open ();
  6. Console.readkey ();
  7. }


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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.