积极答复者
为什么无法捕捉WCF异常?

问题
-
类似如下代码:
Dim sc As New Sjfw.Service1Client
Try
sc.GetDataTable()
Catch ex As EntryPointNotFoundException
Me.ToolStripStatusLabel1.Text = ex.Message
Catch ex As ServiceModel.FaultException
Me.ToolStripStatusLabel1.Text = ex.MessageEnd Try
当WCF未启动时,会发生EndpointNotFoundException,但调试时,程序中断,并未按预期的那样,在状态栏显示错误。
韩立学
- 已编辑 大海怪 2015年6月3日 9:44
答案
全部回复
-
谢谢回复!
加入下述语句后,程序不会退出,但也没有象预期的那样,在ToolStripStatusLabel1上显示错误信息:
Catch ex As Exception
Me.ToolStripStatusLabel1.Text = ex.Message完整语句块:
Dim sc As New Sjfw.Service1ClientTry
sc.GetDataTable()
Catch ex As EntryPointNotFoundException
Me.ToolStripStatusLabel1.Text = ex.Message
Catch ex As ServiceModel.FaultException
Me.ToolStripStatusLabel1.Text = ex.MessageCatch ex As Exception
Me.ToolStripStatusLabel1.Text = ex.MessageEnd Try
调试输出窗口信息:
“System.ServiceModel.EndpointNotFoundException”类型的第一次机会异常在 mscorlib.dll 中发生
未捕捉Exception时,程序中断时的信息:
未处理System.ServiceModel.EndpointNotFoundException
HResult=-2146233087
Message=没有终结点在侦听可以接受消息的 http://localhost:8733/Design_Time_Addresses/Sjfw/Service1/。这通常是由于不正确的地址或者 SOAP 操作导致的。如果存在此情况,请参见 InnerException 以了解详细信息。
Source=mscorlib
而我希望在用户界面上显示相关信息。
如果能在使用服务前,测试服务的状态,则更好!
韩立学
-
是不是 缺少Endpoint?检查下配置文件 和代码
Frank Xu Lei--谦卑若愚,好学若饥
[老徐的网站]:http://www.frankxulei.com/[老徐的博客]:http://54peixun.com/Author/frankxulei
微软WCF中文技术论坛
微软WCF英文技术论坛
微软WCF技术群:166599314 -
是不是 缺少Endpoint?检查下配置文件 和代码
Frank Xu Lei--谦卑若愚,好学若饥
[老徐的网站]:http://www.frankxulei.com/[老徐的博客]:http://54peixun.com/Author/frankxulei
微软WCF中文技术论坛
微软WCF英文技术论坛
微软WCF技术群:166599314