.net WCF呼叫有时会无声地失败
我实现了一个单向wcf方法。我按照本文中提到的方法来处理webservice调用,我使用下面的类来调用web服务.net WCF呼叫有时会无声地失败,.net,wcf,.net,Wcf,我实现了一个单向wcf方法。我按照本文中提到的方法来处理webservice调用,我使用下面的类来调用web服务 public delegate void UseServiceDelegate<T>(T proxy); public static class Service<T> { public static ChannelFactory<T> _channelFactory = new ChannelFactory<T>("*");
public delegate void UseServiceDelegate<T>(T proxy);
public static class Service<T>
{
public static ChannelFactory<T> _channelFactory = new ChannelFactory<T>("*");
public static void Use(UseServiceDelegate<T> codeBlock)
{
IClientChannel proxy = (IClientChannel)_channelFactory.CreateChannel();
bool success = false;
try
{
codeBlock((T)proxy);
proxy.Close();
success = true;
}
finally
{
if (!success)
{
proxy.Abort();
}
}
}
}
Service<IOrderService>.Use(orderService=>
{
orderService.PlaceOrder(request);
}
您可以使用.在try语句中添加catch块,查看输出中是否有任何描述性内容,如果您不想在此处处理错误,则至少记录消息
catch (Exception ex0)
{
// Log exception here
throw; // will rethrow the same exception to outside
}
这样,如果您错过/忘记处理异常,至少您会有一个异常日志我在调用此服务的地方实现了try/catch块。那么您在这个try-catch块中写入的日志呢,它不是精确指出了静默故障的原因吗?根本没有引发异常,我们找不到任何错误(可能会有很多来自不同用户的并发请求。我认为其中一些请求会被忽略。)。。
catch (Exception ex0)
{
// Log exception here
throw; // will rethrow the same exception to outside
}