繁体   English   中英

如果Web服务或窗口服务关闭,如何捕获异常?

[英]How to catch exception if a webservice or a window service is down?

我知道它很愚蠢,但是我想知道在Web服务关闭的情况下使用哪个Exception类。我将Web服务的url地址更改为其他名称,因此它引发了异常,例如“没有端点列表。 “

一旦遇到上述记录,应以适当的例外捕获它。

下面是我用于超时异常的代码。 N现在我想处理没有列出端点的异常。

try
        {
            var result = proxy.Geocode(ADDRESSVERIFICATIONAPISOURCE);
            if (result != null)
            {
                // Display result of geocoding result.
                retAddresses.AddRange(
                    result.Select(
                        item =>
                        new AddressContent
                        {
                            Address = item.GeocodedAddress.Address,
                            City = item.GeocodedAddress.City,
                            State = item.GeocodedAddress.State,
                            Zip = item.GeocodedAddress.Zip,
                            Status = item.Status,
                            StatusFlag = item.StatusFlag,
                            SourceId = item.GeocodedAddress.SourceId
                        }));
            }
        }
        catch (TimeoutException ex)
        {
            retAddresses.AddRange(
                   addresses.Select(
                       item =>
                       new AddressContent
                       {
                           Status = null,
                           StatusFlag = item.StatusFlag,
                           SourceId = item.SourceId
                       }));
        }            
        catch
        {
            retAddresses.AddRange(
                    addresses.Select(
                        item =>
                        new AddressContent
                        {
                            Status = "N",
                            StatusFlag = item.StatusFlag,
                            SourceId = item.SourceId
                        }));
        }
//Here I want to handle exception if service is down 

任何帮助表示赞赏。

谢谢,

我得到了答案。 我使用了EndpointNotFoundException ,它起作用了。 谢谢大家的帮助。

谢谢,

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM