我有一台使用NetTcp双工通道的服务器/客户端,我试图弄清楚在mono(v2.10.8)下运行它需要多少工作。
有人能告诉我如何正确地将FaultException抛出到在mono下运行的客户端吗?或者如果不完全支持?
合同定义为:
[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中的单声道命令提示符下运行客户端时,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块接收,或者我没有做到这一点?