2

I am getting below exception when I try to host a WCF service:

Service 'WcfServiceLibrary3.Service1' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.

I am using the folowing code:

using (System.ServiceModel.ServiceHost host = new System.ServiceModel.ServiceHost(typeof(WcfServiceLibrary1.Service1)))//Line 1
        {
            host.Open();

            Console.WriteLine("Service started. press any key to stop it");
            Console.ReadLine();
            host.Close();
        }

This error come at line 1. Can anyone help to resolve this Exception.

  • Can you post what you have done i.e. your service interface, the config file that you are using for us to help you out – Rajesh Jun 05 '13 at 10:07
  • Can the upvoters perhaps comment on why they think this is a useful question that shows research effort? – CodeCaster Jun 05 '13 at 13:09
  • @CodeCaster, Now is it looking like some research work :)? – dipen singh Jun 05 '13 at 13:29
  • Sorry, but no. Search the web for "Service has zero application (non-infrastructure) endpoints", you might find questions like [this one](http://stackoverflow.com/questions/2328840/service-has-zero-application-non-infrastructure-endpoints) that exactly describe the problem and possible solutions. Try each and every one of them, document what happens if you try them, and _then_ ask a question where you show which possible solutions you have tried and why they did not work. **That** is what is meant with showing research effort. Simply pasting you code and the error it returns isn't. – CodeCaster Jun 05 '13 at 13:31

2 Answers2

2

If you are using a console application to host service and defined your service in another class library, then you need to use the app.config in correct way.

Try to add app.config into console application in which you are hosting the service.

Also match the name of service and base url.

hope this code will help in hosting the service:

static void Main(string[] args)
    {
        // Create the ServiceHost.
        using (ServiceHost host = new ServiceHost(typeof(HelloWorldService)))
        {
            host.Open();

            Console.WriteLine("The service is ready at {0}", baseAddress);
            Console.WriteLine("Press <Enter> to stop the service.");
            Console.ReadLine();

            // Close the ServiceHost.
            host.Close();
        }
    }
Sanjeev Rai
  • 6,721
  • 4
  • 23
  • 33
1

It seems that you have not added reference of your created service in your application.

You need to right click on your application.

Select option as add service reference.

Paste link [Address] to service.

Give name to instance.

This will sort problem. Follow this approach.

halfer
  • 19,824
  • 17
  • 99
  • 186
Freelancer
  • 9,008
  • 7
  • 42
  • 81