我试图在SO上扩展这个答案,使WCF客户端在瞬态网络故障时重试,并处理需要重试的其他情况,例如身份验证到期.
题:
什么是需要处理的WCF异常,以及处理它们的正确方法是什么?
以下是一些我希望看到的示例技术,而不是proxy.abort():
由于一个人不太可能知道解决它们的所有例外或方法,因此请分享您所知道的内容.我将在下面的代码示例中汇总答案和方法.
// USAGE SAMPLE
//int newOrderId = 0; // need a value for definite assignment
//Service<IOrderService>.Use(orderService=>
//{
// newOrderId = orderService.PlaceOrder(request);
//}
/// <summary>
/// A safe WCF Proxy suitable when sessionmode=false
/// </summary>
/// <param name="codeBlock"></param>
public static void Use(UseServiceDelegateVoid<T> codeBlock)
{
IClientChannel proxy = (IClientChannel)_channelFactory.CreateChannel();
bool success = false;
try
{
codeBlock((T)proxy);
proxy.Close();
success = true;
}
catch (CommunicationObjectAbortedException e)
{
// Object …Run Code Online (Sandbox Code Playgroud) 我们收到此错误:
System.ServiceModel.ServerTooBusyException:RM Destination拒绝了创建可靠会话的请求.服务器'net.tcp:// localhost:50000 /'太忙,无法处理此请求.稍后再试.该频道无法打开.
据我了解,我需要在ReliableSession绑定中增加MaxPendingChannels的值.
但是我们在这样的代码中配置WCF:
serviceHost = new ServiceHost(typeof(MyServiceClass));
ServiceEndpoint endPoint = serviceHost.AddServiceEndpoint(
typeof(IMyService),
new NetTcpBinding(SecurityMode.None, true),
endPointAddress);
Run Code Online (Sandbox Code Playgroud)
那么如何以编程方式设置ReliableSession.MaxPendingChannels?(我可以找到的所有示例都使用配置文件)
在此网页上搜索MaxPendingChannels 有一个选项,但它似乎过于复杂.