求教调用WCF超时问题的解决办法

求教调用WCF超时问题的解决办法,第1张

在 Silverlight 端设置 SendTimeout 和 ReceiveTimeout 属性,经常在 Debug 时需要调试上好几分钟、或者放上几十分钟。

可以在 ServiceReferences.ClientConfig 中配置,不过个人习惯使用后台代码,毕竟配置最灵活:

BasicHttpBinding 在 Debug/ Release 时的代码配置

C# code

defaultBasicHttpBinding = new BasicHttpBinding(BasicHttpSecurityMode.None)

{

Name = "DefaultBasicHttpBinding",

OpenTimeout = new TimeSpan(0, 1, 0),

CloseTimeout = new TimeSpan(0, 1, 0),

#if DEBUG

SendTimeout = new TimeSpan(0, 18, 00),

ReceiveTimeout = new TimeSpan(18, 18, 00),

MaxBufferSize = int.MaxValue,

MaxReceivedMessageSize = int.MaxValue

#else

SendTimeout = new TimeSpan(0, 8, 00),

ReceiveTimeout = new TimeSpan(0, 18, 00),

MaxBufferSize = int.MaxValue,

MaxReceivedMessageSize = int.MaxValue

#endif

}

CustomBinding

C# code

 

customBinding = new CustomBinding()

{

Name = "CustomBinding",

OpenTimeout = new TimeSpan(0, 1, 0),

CloseTimeout = new TimeSpan(0, 1, 0),

#if DEBUG

SendTimeout = new TimeSpan(0, 18, 00),

ReceiveTimeout = new TimeSpan(18, 18, 00),

#else

SendTimeout = new TimeSpan(0, 8, 00),

ReceiveTimeout = new TimeSpan(0, 18, 00),

#endif

}

customBinding.Elements.Add(new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement())

customBinding.Elements.Add(new HttpTransportBindingElement()

{

MaxBufferSize = int.MaxValue, MaxReceivedMessageSize= int.MaxValue

}

)

你应该在connection string中使用attach方式加载并连接数据库的吧。这个需要sql server express才工作。 安装Visual Studio默认会安装相应版本的sql server express.

public int SaveAssessmentEmp(Guid mainId, string selfEvaluation, string deptSuggest, string transferIdea)

{

var item = repository.GetData(mainId)

if (item != null)

{

item.SelfEvaluation = selfEvaluation

item.DeptSuggest = deptSuggest

item.TransferIdea = transferIdea

return repository.Update(item)

}

else return 0

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9583963.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-29
下一篇 2023-04-29

发表评论

登录后才能评论

评论列表(0条)

保存