Search code examples
c#visual-studio-2010appfabricazure-appfabric

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


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.


Solution

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