当前位置: 代码迷 >> ASP.NET >> 创设WCF宿主时出现:服务“System.String”有零个应用程序(非基础结构)终结点。这可能是因为未找到应用程序的配置文件,或者在配置文件中未找到与服务名
  详细解决方案

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

热度:5097   发布时间:2013-02-25 00:00:00.0
创建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"))
            {
                serviceHost.Open();
                Console.WriteLine("The service is ready");
  相关解决方案