2010-06-05 87 views
2

我只是尝试与各种WCF(在.Net 3.0)的情况下。WCF端点异常

我正在使用自托管。

我得到一个异常,因为“Service'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; 
     } 
    } 

} 

,你可以请帮助我了解我在这里错过了什么?

感谢

Lijo

回答

2

你自托管在一个控制台应用程序 - 如何在你的配置设置?

  • MySelfHostConsoleApp项目有app.config文件?

  • 你有MySelfHostConsoleApp.exe.config在与MySelfHostConsoleApp.exe文件相同的目录下吗?

错误消息只是真的意味着配置无法找到,因此无法解释和使用。

更新:另一种选择是WCF不能解释配置,如果它存在。

检查了这一点:

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

  • 然而,在你的配置,你打电话给你的服务:

    <service name="Lijo.Samples.NameDecorator" 
    

这不起作用!您在这里将.NET命名空间和服务命名空间混合在一起 - 并且您需要在服务端配置中放置的名称是.NET完全限定类型名称(包括.NET命名空间 - 而不是服务命名空间! )。

您的服务主机会根据您的代码寻找条目<service name="MyServiceLibrary.NameDecorator"> - 但它不会找到它。

所以,你需要确保这两点同步上涨 - 完全合格的服务类名(包括命名空间和所有)MUST比赛在<service>标签name="...."属性在你的配置。

+0

Hi Marc,在Hsot项目中添加了app.config,并在bin \ Debug中创建了“MySelfHostConsoleApp.exe.config”。我仍然得到例外。 – Lijo 2010-06-05 14:24:48

+0

@Lijo:更新我的答案 - 试试。 – 2010-06-05 15:07:42

+1

谢谢马克。我有一个新的学习。 - app.config中的“服务名称”是实现合同的类名,以及它的名称空间。它与合同的命名空间无关。 – Lijo 2010-06-05 15:25:28