日期:2014-05-17  浏览次数:20458 次

创建WCF宿主时出现:服务“System.String”有零个应用程序(非基础结构)终结点。这可能是因为未找到应用程序的配置文件,或者在配置文件中未找到与服务名

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"))
            {
             &nbs