开发者

WCF endpoint exception

I am just trying with various WCF(in .Net 3.0) scenarios.

I am using self hosting.

I am getting an exception as "Service 'MyServiceLibrary.NameDecorator' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element."

I have a config file as follows (which has an endpoint)

<?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>

And a Host as

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();
        }
    }


}

My Service is as follows

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;
        }
    }

}

Could you please help me to understand what I am missing here?

Thanks

Lijo


You're self-hosting in a console app - how is your config set up??

  • Does your MySelfHostConsoleApp project have an app.config file?

  • Do you have the MySelfHostConsoleApp.exe.config in the same directory as the MySelfHostConsoleApp.exe file?

The error message just really means the config cannot be found and thus cannot be interpreted and used.

UPDATE: the other option is that WCF cannot interpret the config if it's present.

Check this out:

  • in your .NET code, your service class that implements the service is called MyServiceLibrary.NameDecorator

  • however, in your config, you call your service:

    <service name="Lijo.Samples.NameDecorator"
    

That's not going to work! You're mixing up the .NET namespaces and the service namespaces here - and the name you need to put in your service-side config is the .NET fully qualified type name (including the .NET namespace - not the service namespace!).

Your service host will look for an entry <service name="MyServiceLibrary.NameDecorator"> based on your code - but it won't find it.

So you need to make sure to sync those two things up - the fully qualified service class name (including namespace and all) MUST match the name="...." attribute in your <service> tag in your config.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜