【发布时间】:2009-04-28 14:20:53
【问题描述】:
我有一个使用 ASP.net Web 服务的 Windows 窗体客户端。
据我了解,当 Web 服务引发异常时,它将在 .net 客户端软件中转换为 SoapException。
好吧,我正在捕获 SoapException,但是当我在消息框中显示客户端上的消息时,它显示的信息比我真正想要显示的要多。
这是网络服务代码:
throw new ApplicationException("Invalid username or password.");
甚至:
throw new SoapException("Invalid username or password.", SoapException.ServerFaultCode);
但是在客户端,SoapException 的 Message 属性是这样的:
System.Web.Services.Protocols.SoapException:用户名或密码无效。在 C:\Documents and Settings\rdoverby\My Documents\Visual Studio 2008\WebSites\www.gtcc.edu\App_Code\webservices\Transportation.cs:line 中的 Transportation.InsertSignUps(String username, String password, SignUp[] signUps) 50
然而,我真正想展示的是:
用户名或密码无效。
如何从 SoapException 中仅提取原始异常消息。我在 VS 调试器中查看了 SoapException 对象,但找不到我要查找的内容。
谢谢。
编辑
当然,我不想解析那个长字符串。
【问题讨论】:
-
我一直在努力解决这个问题,创建一个带有错误消息的简单响应类是最好的选择。看到这个问答:stackoverflow.com/q/32058/945875
标签: .net web-services exception soap exception-handling