0

Windows Azure 用の appFabric のサービスを起動しようとしています。私は EchoService を実装しています。ちなみに、IEchoContract インターフェイスを実装する必要があります。これらはすべてサーバー側で行います。だから私はこのように進みます。

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

そして EchoSEvice.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;
        }
    }}}

2 つのエラーが発生しました。私は C# の専門家ではありません。最初の 1 つ: EchoService を配置したとき: IEchoContract を取得しました

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

パブリック インターフェイス IEchoContract を配置したときの 2 番目

'IEchoContract' : interfaces declare types

だから助けてください。どうも。

4

4 に答える 4

2

インターフェイスとクラスを 2 回宣言しました。それぞれを 1 回だけ宣言します。

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;
        }
    }
}
于 2011-03-01T12:10:29.817 に答える
1

コードに表示されている場合は、EchoServiceというクラス内にEchoSeviceというクラスがあります。

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

ここでは意味がないため、外部クラスを削除してみてください

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

外部インターフェイスも2回定義されているため、外部インターフェイスも削除する必要があります(おそらく、クラスも2回定義された理由です)。

于 2011-03-01T12:11:29.450 に答える
0

EchoService.cs では、その上にクラス EchoService が既にあるため、内部クラス EchoService を呼び出すことはできません。それらのいずれかの名前を変更する必要があります。

于 2011-03-01T12:10:07.647 に答える
0

EchoService クラスで EchoService クラスを定義しますが、これは不可能です。外側の「class EchoService」を削除するだけで問題ありません。

于 2011-03-01T12:11:18.493 に答える