C# errors: member names cannot be the same as their enclosing type and interfaces declare types

404Dreamer_ML picture 404Dreamer_ML · Mar 1, 2011 · Viewed 10.7k times · Source

I am trying to lauch a service for appFabric for windows Azure. I am implement and EchoService and i need to implement by the way and IEchoContract interface, all of this on server side. So I proceed like this.

On the IEchoContract.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;


namespace Service
{
[ServiceContract(Name = "EchoContract", Namespace = "http://samples.microsoft.com/ServiceModel/Relay/")]
interface IEchoContract
{
    public interface IEchoContract
    {
        [OperationContract]
        string Echo(string text);
    }
}}

And on EchoSErvice.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace Service
{
class EchoService
{
    [ServiceBehavior(Name = "EchoService", Namespace = "http://samples.microsoft.com/ServiceModel/Relay/")]
    public class EchoService : IEchoContract
    {
        public string Echo(string text)
        {
            Console.WriteLine("Echoing: {0}", text);
            return text;
        }
    }}}

I got two errors, i am not an expert on C# So first one: When i put EchoService : IEchoContract i got

'EchoService': member names cannot be the same as their enclosing type

Second when i put public interface IEchoContract

'IEchoContract' : interfaces declare types

So please help. Thx.

Answer

Andrew Hare picture Andrew Hare · Mar 1, 2011

You have declared the interface and the class twice - declare each just once.

IEchoContract.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace Service
{
    [ServiceContract(Name = "EchoContract", Namespace = "http://samples.microsoft.com/ServiceModel/Relay/")]
    public interface IEchoContract
    {
        [OperationContract]
        string Echo(string text);
    }
}

EchoService.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace Service
{
    [ServiceBehavior(Name = "EchoService", Namespace = "http://samples.microsoft.com/ServiceModel/Relay/")]
    public class EchoService : IEchoContract
    {
        public string Echo(string text)
        {
            Console.WriteLine("Echoing: {0}", text);
            return text;
        }
    }
}