1

WCF チュートリアル - 基本的なプロセス間通信に関するこのブログ エントリから派生したこの例を実行しようとしています。

サーバー コードを .NET4 で実行すると、次の例外がスローされます。

First-chance exception at 0x754cd36f (KernelBase.dll) in TestConsole.exe: 0xE0564552: 0xe0564552.

サーバー コードを .NET3.5 で実行すると、問題なく動作します。クライアント コードは、両方のテストで .NET4 に対してコンパイルされます。私のサーバーコードは次のとおりです。

[ServiceContract]
public interface IStringReverser
{
    [OperationContract]
    string ReverseString(string value);
}

public class StringReverser : IStringReverser
{
    public string ReverseString(string value)
    {
        char[] retVal = value.ToCharArray();
        int idx = 0;
        for (int i = value.Length - 1; i >= 0; i--)
            retVal[idx++] = value[i];

        return new string(retVal);
    }
}

class Program
{
    static void Main(string[] args)
    {
        using (ServiceHost host = new ServiceHost(typeof(StringReverser), new Uri[] { new Uri("net.pipe://localhost") }))
        {
            host.AddServiceEndpoint(typeof(IStringReverser), new NetNamedPipeBinding(), "PipeReverse");
            host.Open();

            Console.WriteLine("Service is available. Press <ENTER> to exit.");
            Console.ReadLine();

            host.Close();
        }
    }
}

私のクライアントコードは次のとおりです。

[ServiceContract]
public interface IStringReverser
{
    [OperationContract]
    string ReverseString(string value);
}

class Program
{
    static void Main(string[] args)
    {
        ChannelFactory<IStringReverser> pipeFactory =
          new ChannelFactory<IStringReverser>(
            new NetNamedPipeBinding(),
            new EndpointAddress(
              "net.pipe://localhost/PipeReverse"));

        IStringReverser pipeProxy = pipeFactory.CreateChannel();

        while (true)
        {
            string str = Console.ReadLine();
            Console.WriteLine("pipe: " +
              pipeProxy.ReverseString(str));
        }
    }
}

なぜこれが.NET4で失敗するのですか? かなり基本的な例のようです。各実行の間にクリーン/ビルドを行いました。実際のスタックトレースのスナップショットは次のとおりです。

ここに画像の説明を入力

4

1 に答える 1

1

Visual Studio で [Debug] -> [Exceptions] -> [C++ Exceptions] で「throw」をチェックしていたことがわかりました。例外をスローせずに処理させれば、すべて正常に動作します。

于 2012-08-08T16:42:30.933 に答える