【发布时间】:2009-09-30 15:15:23
【问题描述】:
我检查了其余的远程问题,但这个具体案例似乎没有得到解决。
我设置了一个 .NET Remoting 服务器/客户端。在服务器端,我有一个对象,它带有一个可以抛出异常的方法,以及一个将尝试调用该方法的客户端。
服务器:
public bool MyEquals(Guid myGuid, string a, string b)
{
if (CheckAuthentication(myGuid))
{
logger.Debug("Request for \"" + a + "\".Equals(\"" + b + "\")");
return a.Equals(b);
}
else
{
throw new AuthenticationException(UserRegistryService.USER_NOT_REGISTERED_EXCEPTION_TEXT);
}
}
客户:
try
{
bool result = RemotedObject.MyEquals(myGuid, "cat", "dog");
}
catch (Services.Exceptions.AuthenticationException e)
{
Console.WriteLine("You do not have permission to execute that action");
}
当我使用导致 CheckAuthentication 返回 false 的 Guid 调用 MyEquals 时,.NET 尝试抛出异常并说 AuthenticationException 未处理。这发生在服务器端。异常永远不会被编组到客户端,我不知道为什么。我看过的所有问题都解决了在客户端处理异常的问题,但它不是自定义异常而是基本类型。就我而言,我什至没有任何异常可以跨越远程边界到客户端。这是 AuthenticationException 的副本。它在服务器和客户端之间的共享库中。
[Serializable]
public class AuthenticationException : ApplicationException, ISerializable
{
public AuthenticationException(string message)
: base(message)
{
}
public AuthenticationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
#region ISerializable Members
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
}
#endregion
}
【问题讨论】:
标签: c# .net exception-handling remoting