0

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.

404Dreamer_ML
  • 890
  • 3
  • 14
  • 25

4 Answers4

2

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;
        }
    }
}
Andrew Hare
  • 344,730
  • 71
  • 640
  • 635
1

If you see in your code you have a class called EchoSevice inside a class called EchoService

namespace Service
{
  class EchoService
  {
    [ServiceBehavior(Name = "EchoService", Namespace = "http://samples.microsoft.com/ServiceModel/Relay/")]
    public class EchoService : IEchoContract
    ...

Try removing the outer class as it has no meaning here

namespace Service
{
  [ServiceBehavior(Name = "EchoService", Namespace = "http://samples.microsoft.com/ServiceModel/Relay/")]
  public class EchoService : IEchoContract
  ...

You will have to remove your outer interface also, since those are also defined twice (probably the reason why your classes ended up defined twice as well)

Øyvind Bråthen
  • 59,338
  • 27
  • 124
  • 151
  • @404 - Please post your now updated interface and class as an edit above so we can see what the problem is after you have fixed up according to the directions you have been given by the questions. – Øyvind Bråthen Mar 01 '11 at 13:34
0

In EchoService.cs, you can't call the internal class EchoService as you already have a class EchoService above it. You need to rename one of them.

Andrew Hare
  • 344,730
  • 71
  • 640
  • 635
Ian Devlin
  • 18,534
  • 6
  • 55
  • 73
0

You define an EchoService class in the EchoService class - that is not possible. Just remove the outer "class EchoService" and you should be fine.

TheEye
  • 9,280
  • 2
  • 42
  • 58