【问题标题】:WCF endpoint exceptionWCF 端点异常
【发布时间】:2010-06-05 13:44:30
【问题描述】:

我只是在尝试各种 WCF(在 .Net 3.0 中)场景。

我正在使用自托管。

我收到一个异常,因为“服务 'MyServiceLibrary.NameDecorator' 有零个应用程序(非基础设施)端点。这可能是因为找不到您的应用程序的配置文件,或者因为没有匹配服务名称的服务元素可能是在配置文件中找到,或者因为在服务元素中没有定义端点。”

我有一个如下配置文件(有一个端点)

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <system.serviceModel>
    <services>

      <service name="Lijo.Samples.NameDecorator"
               behaviorConfiguration="WeatherServiceBehavior">

        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8010/ServiceModelSamples/FreeServiceWorld"/>
          </baseAddresses>
        </host>

        <endpoint address=""
                  binding="wsHttpBinding"
                  contract="Lijo.Samples.IElementaryService" />
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WeatherServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

和一个主机作为

using System.ServiceModel;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Runtime.Serialization;

namespace MySelfHostConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            System.ServiceModel.ServiceHost myHost = new ServiceHost(typeof(MyServiceLibrary.NameDecorator));
            myHost.Open(); 
            Console.ReadLine();
        }
    }


}

我的服务如下

using System.ServiceModel;
using System.Runtime.Serialization;

namespace MyServiceLibrary
{
    [ServiceContract(Namespace = "http://Lijo.Samples")]
    public interface IElementaryService
    {
        [OperationContract]
        CompanyLogo GetLogo();
    }

    public class NameDecorator : IElementaryService
    {
        public CompanyLogo GetLogo()
        {

            CircleType cirlce = new CircleType();
            CompanyLogo logo = new CompanyLogo(cirlce);
            return logo;
        }
    }

    [DataContract]
    public abstract class IShape 
    {
        public abstract string SelfExplain();

    }

    [DataContract(Name = "Circle")]
    public class CircleType : IShape 
    {
        public override string SelfExplain()
        {
            return "I am a Circle";
        }
    }

    [DataContract(Name = "Triangle")]
    public class TriangleType : IShape
    {
        public override string SelfExplain()
        {
            return "I am a Triangle";
        }
    }

    [DataContract]
    [KnownType(typeof(CircleType))]
    [KnownType(typeof(TriangleType))]
    public class CompanyLogo
    {
        private IShape m_shapeOfLogo;

        [DataMember]
        public IShape ShapeOfLogo
        {
            get
            {
                return m_shapeOfLogo;
            }
            set
            {
                m_shapeOfLogo = value;
            }
        }

        public CompanyLogo(IShape shape)
        {
            m_shapeOfLogo = shape;
        }
    }

}

您能帮我理解我在这里缺少什么吗?

谢谢

李乔

【问题讨论】:

    标签: wcf


    【解决方案1】:

    您在控制台应用程序中自托管 - 您的配置是如何设置的??

    • 您的MySelfHostConsoleApp 项目是否有app.config 文件?

    • MySelfHostConsoleApp.exe.config 是否与MySelfHostConsoleApp.exe 文件位于同一目录中?

    错误信息实际上意味着无法找到配置,因此无法解释和使用。

    更新:另一个选项是 WCF 无法解释配置(如果存在)。

    看看这个:

    • 在您的 .NET 代码中,实现该服务的服务类称为 MyServiceLibrary.NameDecorator

    • 但是,在您的配置中,您调用了您的服务:

      <service name="Lijo.Samples.NameDecorator"
      

    那是行不通的!您在这里混合了 .NET 命名空间和服务命名空间 - 您需要放入服务端配置的名称是 .NET 完全限定类型名称(包括 .NET 命名空间 - not 服务命名空间!)。

    您的服务主机将根据您的代码查找条目&lt;service name="MyServiceLibrary.NameDecorator"&gt; - 但它不会找到它。

    因此,您需要确保同步这两件事 - 完全限定的服务类名称(包括命名空间和所有)必须与您的 &lt;service&gt; 标记中的 name="...." 属性匹配配置。

    【讨论】:

    • 嗨 Marc,在 Hsot 项目中添加了 app.config,并在 bin\Debug 中创建了“MySelfHostConsoleApp.exe.config”。我仍然遇到异常。
    • @Lijo:更新了我的答案 - 试试吧。
    • 谢谢马克。我有了新的学习。 - app.config 中的“服务名称”是实现合约的类名,带有其命名空间。与合约的命名空间无关。
    • 解决了我的问题。谢谢。
    猜你喜欢
    • 2023-04-01
    • 1970-01-01
    • 2012-05-07
    • 1970-01-01
    • 2011-04-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多