您的位置:首页 > 其它

.Net Remoting的研究学习:如何获得服务器端产生的错误

2007-09-10 15:26 555 查看
困扰我几天的问题终于解决了,新手就是新手,一个小问题往往都能困着你好几天!当然,当你解决掉他的时候的那种心情,那简直是无法比拟的,好比你一直便秘,蹲厕所腿都蹲麻了,就在你要放弃提裤子的时候,突然哄的一声,全通了,那滋味,自己想去吧。。。比喻不太恰当,看不下去的请关掉去趟厕所先啊!

我所遇到的问题是这样的:使用.net remoting开发项目,过程遇到一些BUG讯息,当我以自己电脑为服务器,也就是DEBUG模式的时候可以显示错误讯息,当通过服务器(另一个电脑)测试就出现一行“Server encountered an internal error. For more information, turn off customErrors in the server's .config file.”大概意思就是服务器错了,配置什么什么文件,就看不太懂了,其实改变下文件就应该可以的,我就是那么笨,没办法,算是个教训吧!

目前利用.net remoting开发三层架构系统,在中间层有catch语句,在debug本机模式下测试消息是可以通过remoting传递到前端显示,在远程测试的时候就总会出现同一错误“Server encountered an internal error. For more information, turn off customErrors in the server's .config file”!

在CSDN找到一方案
http://topic.csdn.net/t/20050603/15/4057264.html
但是按照所说的继承类后,catch无法认识这个类,出现错误并跳到相应的代码处!表明并未捕捉到!请问各位如何解决?

我所做的方式是,新建一类继承Exception,代码如下:

[Serializable()]

public class CustomException : System.Exception, ISerializable

{

public CustomException(string asMessage, Exception aeinner)

: base(asMessage, aeinner)

{ }

public CustomException()

: base()

{ }

public CustomException(string asMessage)

: base(asMessage)

{

}

protected CustomException(SerializationInfo asinfo, StreamingContext asContext)

: base(asinfo, asContext)

{

}

[SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter

= true)]

public override void GetObjectData(SerializationInfo asinfo, StreamingContext asContext)

{

base.GetObjectData(asinfo, asContext);

}

}

中间层方法如下:

public static string TestCatchMessage()

{

string sMessage = "这是一个异常讯息,如果接收正常,则说明中间层可以发送异常讯息到底前端!";

throw new ClbError.CustomException(sMessage);

return "Failure";

}

在前端.net remoting机制配置和接口都没有代码问题,

接口如下:

Public interface iGetData

{

String TestCatchMessage();

}

前端调用代码如下:

try

{

MessageBox.Show(FrontRemoting.Remoting.TestCatchMessage());

}

catch (ClbError.CustomException e)

{

string sErr1 = ClbError.ClsError.ShowErrorMessage(e);

FrontHelper.ShowMsg(sErr1);//自己写的弹出窗体方法

return;

}

异常状况为:跳转到错误的代码处,不认识ClbError.CustomException 类!

请教各位大侠如何解决?

通过BAIDU搜索大多是新建自定义Exception类,找到不少答案,但对我好像都没用,我觉得错误不在这里,Exception应该是可以传递到前面的,否则就不讲究了!
http://blog.gurock.com/articles/creating-custom-exceptions-in-dotnet/ http://www.c-sharpcorner.com/UploadFile/susanabraham/CustomExceptionHandling06022005011154AM/CustomExceptionHandling.aspx http://msdn.microsoft.com/msdnmag/issues/04/03/ExceptionsinCOM/#S2
这三篇文章说明的是如何建立Custom Exception类

试了很多遍,就是不行,后来才重视英语,复制那段英语去Google了一下,第一个没看明白!第二个就是正解!
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1781771&SiteID=1
原来在

TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;

几句话就可以了,超级简单的问题让我忙了老半天,归纳一下,自己对.net 的机制还不熟悉,基础不牢靠!恩,加油!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: