【问题标题】:WCF over Named Pipes throws exception in .NET4, works in 3.5WCF over Named Pipes 在 .NET4 中引发异常,适用于 3.5
【发布时间】:2012-08-04 22:47:41
【问题描述】:

我正在尝试运行这个源自
WCF Tutorial - Basic Interprocess Communication
上的博客条目的示例

如果我在 .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 上会失败?似乎是一个非常基本的例子。我确实在每次运行之间进行了清理/构建。这是实际堆栈跟踪的快照:

【问题讨论】:

    标签: wcf .net-4.0 .net-3.5 named-pipes


    【解决方案1】:

    事实证明,我在 Visual Studio 中的调试 -> 异常 -> C++ 异常中检查了“抛出”。如果我不抛出异常,而是让它被处理,一切正常。

    【讨论】:

      猜你喜欢
      • 2010-09-21
      • 1970-01-01
      • 2021-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-01
      • 1970-01-01
      • 2017-10-05
      相关资源
      最近更新 更多