Goo*_*ber 23 .net c# wcf exception-handling
本来:
场景:
码:
[DataContract(IsReference=true)]
public class Message
{
[DataMember]
public string TopicName { get; set; }
[DataMember]
public string EventData { get; set; }
[DataMember]
public SerializableDictionary<string, FuturesLineAsset> FuturesLineDictionary { get; set ; }
}
Run Code Online (Sandbox Code Playgroud)
思考:
家长:
public class FuturesAsset
{
public string AssetName { get; set; }
public BindableDictionary<string, FuturesLineAsset> AssetLines { get; private set; }
public FuturesAsset()
{
AssetLines = new BindableDictionary<string, FuturesLineAsset>();
}
public FuturesAsset(string assetName)
{
AssetLines = new BindableDictionary<string, FuturesLineAsset>();
AssetName = assetName;
}
}
Run Code Online (Sandbox Code Playgroud)
儿童:
public class FuturesLineAsset
{
public string ReferenceAsset { get; set; }
public string MID { get; set; }
public double LivePrice { get; set; }
public DateTime UpdateTime { get; set; }
public DateTime LastContributedTime { get; set; }
public double Spread { get; set; }
public double Correlation { get; set; }
public DateTime Maturity { get; set; }
public double ReferenceCurve { get; set; }
public FuturesLineAsset(string mID, string referenceAsset, double livePrice)
{
MID = mID;
ReferenceAsset = referenceAsset;
ReutersLivePrice = livePrice;
}
}
Run Code Online (Sandbox Code Playgroud)
Adr*_*n T 19
这个错误可能是由许多事情引起的.虽然在这种情况下这是一个时间问题,但它通常与时间无关,特别是如果立即收到错误.可能的原因是:
the*_*onk 13
该异常与循环引用无关,当您尝试通过线路抽取大量数据时,它只是完全超时.
WCF附带的默认值非常低(我相信这些在WCF 4中已经更改).阅读这两篇博客文章,他们应该让您了解如何解决您的服务:
如何限制Wcf服务,帮助防止DoS攻击,并维护Wcf可伸缩性
更新:此外,WCF配置中有许多不同的超时,并且取决于它是您正在谈论的客户端还是服务器,您需要更新不同的超时子句...请阅读此线程,了解每个意味着什么你应该能够弄清楚你需要碰到哪一个.或者,您可以将每个超时设置为int.max,如果您真的不在乎呼叫是否需要很长时间才能完成.
小智 5
出现此问题的原因是从 Windows 服务主机安装程序的 OnStart 事件调用了较长的初始化过程。通过设置 TCP 绑定的安全模式和超时来修复。
// Create a channel factory.
NetTcpBinding b = new NetTcpBinding();
b.Security.Mode = SecurityMode.Transport;
b.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
b.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign;
b.MaxReceivedMessageSize = 1000000;
b.OpenTimeout = TimeSpan.FromMinutes(2);
b.SendTimeout = TimeSpan.FromMinutes(2);
b.ReceiveTimeout = TimeSpan.FromMinutes(10);
Run Code Online (Sandbox Code Playgroud)