using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;namespace MagicEightBallServiceLib
{
    [ServiceContract]
    public interface IEightBall
    {
        [OperationContract]
        string ObtainAnswer(string userQuestion);
    }
    public class MagicEightBallService:IEightBall
    {
        #region IEightBall 成员
        public MagicEightBallService()
        {
            Console.WriteLine("The magic 8 ball awaits for your answer");
        }
        public string ObtainAnswer(string userQuestion)
        {
            string[] answer = { "Future uncertain", "yes", "no", "Hazy" };
            Random r = new Random();
            return String.Format("{0}?{1}", userQuestion, answer[r.Next(answer.Length)]);
        }        #endregion
    }
}<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="MagicEightBallServiceLib.MagicEightBallService">
        <endpoint address="http://localhost:8080/MagicEightBallService"
                  binding="basicHttpBinding" contract="MagicEightBallServiceLib.IEightBall"/>
      </service>
    </services>
  </system.serviceModel>
</configuration>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using MagicEightBallServiceLib;namespace MagicEightBallServiceHost
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Console basic WCF host");
            using (ServiceHost serviceHost=new ServiceHost("MagicEightBallService"))
            {
                serviceHost.Open();
                Console.WriteLine("The service is ready");
                Console.WriteLine("Press the enter key to terminate");
                Console.ReadLine();
            }
        }
    }
}

解决方案 »

  1.   

    你的Service的名字是:MagicEightBallServiceLib.MagicEightBallService
    你初始化的用的是MagicEightBallService
      

  2.   

    using (ServiceHost serviceHost=new ServiceHost("MagicEightBallService"))改成了using (ServiceHost serviceHost=new ServiceHost("MagicEightBallServiceLib.MagicEightBallService"))还是报错。
      

  3.   

    代码从那里来的?
    自己先看看手册
    http://msdn.microsoft.com/zh-cn/library/system.servicemodel.servicehost.aspx
    打开host那部分不对
      using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService)))
      

  4.   

    我的是WCF服务寄宿用的就是using(ServiceHost host = new ServiceHost(typeof(CalculatorService)))
    可以依然报这个服务有零个应用程序(非基础结构)终结点,求帮忙啊