Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法从我的web服务捕获异常_C#_Web Services - Fatal编程技术网

C# 无法从我的web服务捕获异常

C# 无法从我的web服务捕获异常,c#,web-services,C#,Web Services,我有一个WPF应用程序,它将尝试从web服务(ASMX)获取数据。我在web服务上创建了一个方法,以查看web服务是否可用。但是,我无法捕获返回的异常。以下是我在web服务上调用测试方法的代码: public bool TestConnection() { try { return service.Test(); } catch(Exception ex) { return false; } } Test()方法引

我有一个WPF应用程序,它将尝试从web服务(ASMX)获取数据。我在web服务上创建了一个方法,以查看web服务是否可用。但是,我无法捕获返回的异常。以下是我在web服务上调用测试方法的代码:

public bool TestConnection()
{
    try
    {
        return service.Test();
    }
    catch(Exception ex)
    {
        return false;
    }
}
Test()方法引发异常,因为没有web服务侦听(我更改了url以模拟真实场景)。它抛出的异常没有被我的catch语句捕获。我不明白为什么不。这是我得到的例外:

System.Windows.Markup.XamlParseException occurred
  Message='The invocation of the constructor on type 'GreenWebPlayerWPF.Window1' that matches the specified binding constraints threw an exception.' Line number '4' and line position '258'.
  Source=PresentationFramework
  LineNumber=4
  LinePosition=258
  StackTrace:
       at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
  InnerException: 
       Message=Exception handled
       Source=Player
       StackTrace:
            at GreenWebPlayerWPF.Services.GWDSServiceProxy.Test() in C:\Subversion\GreenWeb 2.5\Version 2.5\GreenWebPlayerWPF\Services\Proxy\GWDSServiceProxy.cs:line 214
            at GreenWebPlayerWPF.HeartBeatService.Start() in C:\Subversion\GreenWeb 2.5\Version 2.5\GreenWebPlayerWPF\Services\HeartBeatService.cs:line 21
            at GreenWebPlayerWPF.Window1..ctor() in C:\Subversion\GreenWeb 2.5\Version 2.5\GreenWebPlayerWPF\Window1.xaml.cs:line 127
       InnerException: 
            Message=Service unavailable:Unable to connect to the remote server
            Source=Player
            StackTrace:
                 at GreenWebPlayerWPF.Services.GWDSServiceProxy.Test() in C:\Subversion\GreenWeb 2.5\Version 2.5\GreenWebPlayerWPF\Services\Proxy\GWDSServiceProxy.cs:line 206
            InnerException: 
这个异常是一个xaml异常,在我有机会抓住它之前,我的异常似乎正在冒泡


有人知道发生了什么吗?

我在堆栈跟踪中没有看到
TestConnection
方法。你确定是用那种方法吗?是
TestConnection
HeartBeatService
还是
Window1
中?是在Heartbeat服务中(失败的是Heartbeat),Heartbeat是BackgroundWorker线程。