【发布时间】:2017-03-20 10:32:26
【问题描述】:
我知道这很愚蠢,但我想知道在 web 服务关闭的情况下使用哪个异常类。我将 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
感谢任何帮助。
谢谢,
【问题讨论】:
-
如果 Web 服务关闭,您会捕获什么异常?如果您不确定,那么为什么不尝试使 Web 服务脱机并运行您的代码,然后查看您捕获的异常。
标签: c# .net web-services