0

我有一个使用 NetTcp 双工通道的服务器/客户端,我试图弄清楚在单声道(v2.10.8)下运行它需要多少工作。

有人能告诉我如何正确地向在单声道下运行的客户端抛出 FaultException 吗?或者如果这不完全支持?

合同定义为:

[OperationContract(IsInitiating = true)]
[FaultContract(typeof(IOException))] 
string ConnectWithFault(string clientVersion, string workstation)

并且服务器端方法将始终生成故障以进行测试:

public string ConnectWithFault(string clientVersion, string workstation)
{
  IOException ioe = new IOException("Testing Fault Contract");
  throw new FaultException<IOException>(ioe, new FaultReason(ioe.Message), new FaultCode("Sender")); 

  return "Should Never Reach Here!";
}

当我在 windows 中正常运行客户端时,一切正常,但是当我在 Windows 中以单命令提示符运行客户端时,FaultException 似乎确实传到了客户端,但我无法正确捕获它。或者当它试图在客户端捕获 FaultException 时是否存在内部单声道错误?我试图抓住几种不同的形式:

public void TestConnectWithFault()
{
  Console.WriteLine("Client->TestConnectWithFault() +");
  try
  {
    string response = RemoteSessionChannel.ConnectWithFault("client1.0", "MY-PC");
    Console.WriteLine("**** DuplexClient->Connect Response: {0}", response);
  }
  catch (FaultException<IOException> ioe)
  {
    Console.WriteLine("Connect failed. (IOException): {0}", ioe.ToString());
  }
  catch (FaultException fe)
  {
    Console.WriteLine("Connect failed. (FaultException): {0}", fe.ToString());
  }
  catch (Exception ex)
  {
    Console.WriteLine("Connect failed. (Exception): {0}", ex.ToString());
  }
  Console.WriteLine("Client->TestConnectWithFault() -");
}

但是我总是在客户端控制台中得到以下输出并且客户端挂起:

Client->TestConnectWithFault() +

**System.ServiceModel.FaultException: Testing Fault Contract
  at System.ServiceModel.MonoInternal.DuplexClientRuntimeChannel.ProcessInputCor
e (IInputChannel input, System.ServiceModel.Channels.Message message) [0x00000]
in <filename unknown>:0
  at System.ServiceModel.MonoInternal.DuplexClientRuntimeChannel.ProcessInput (I
InputChannel input, System.ServiceModel.Channels.Message message) [0x00000] in <
filename unknown>:0**

所以看起来异常正在传递给客户端,但没有被任何 catch 块拾取,或者我没有做对?

4

1 回答 1

1

上周我在 Mono 中修复了错误 #7177 。

我很快对此进行了测试,现在它工作正常。

于 2012-10-01T15:33:09.160 回答