3

コントラクトタイプHelloIndigo.Serviceは、ServiceContractAttributeに関連付けられていません。有効なコントラクトを定義するには、指定されたタイプ(コントラクトインターフェイスまたはサービスクラスのいずれか)をServiceContractAttributeに関連付ける必要があります。

ライブラリクラスを作成し、コンソールアプリケーションでそのクラスを参照します。

ライブラリクラス:

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();
  }
}

コンソールアプリケーション:

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();
      }
    }
  }
}
4

1 に答える 1

7

エンドポイントを追加するときは、コントラクトであるインターフェースを提供する必要があります。

host.AddServiceEndpoint(typeof(HelloIndigo.IHelloIndigoService),
                                new BasicHttpBinding(),"Service");
于 2012-01-07T19:03:36.737 に答える