3

The contract type HelloIndigo.Service is not attributed with ServiceContractAttribute. In order to define a valid contract, the specified type (either contract interface or service class) must be attributed with ServiceContractAttribute.

I build a library class and referenced to the class in the console application.

The library class:

namespace HelloIndigo
{
  public class Service : IHelloIndigoService
  {
      public string HelloIndigo()
      {
        return "Hello Indigo";
      }
  }

  [ServiceContract(Namespace = "http://www.thatindigogirl.com/samples/2006/06")]
  interface IHelloIndigoService
  {
    [OperationContract]
    string HelloIndigo();
  }
}

The console application:

namespace Host
{
  class Program
  {
    static void Main(string[] args)
    {
      using (ServiceHost host = new ServiceHost(typeof(HelloIndigo.Service), 
                                    new Uri("http://localhost:8000/HelloIndigo")))
      {
        host.AddServiceEndpoint(typeof(HelloIndigo.Service),
                                    new BasicHttpBinding(),"Service");
        host.Open();
        Console.WriteLine("Press enter to terminate the host service");
        Console.ReadLine();
      }
    }
  }
}
Anders Abel
  • 67,989
  • 17
  • 150
  • 217
BlackFire27
  • 1,470
  • 5
  • 21
  • 32
  • 1
    Please pay some attention to the formatting of your questions. There is a preview when writing the question, look at it before posting. (I've fixed this one for you). – Anders Abel Jan 07 '12 at 19:06

1 Answers1

7

When you add the endpoint, you should supply the interface that is the contract:

host.AddServiceEndpoint(typeof(HelloIndigo.IHelloIndigoService),
                                new BasicHttpBinding(),"Service");
Anders Abel
  • 67,989
  • 17
  • 150
  • 217