您的位置:首页 > 其它

WCF传输数据量大的问题

2013-08-21 18:46 260 查看
解决方案:WCF承载项目的web.config里添加

<dataContractSerializer maxItemsInObjectGraph="2147483647" />

<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<FONT color=red> <dataContractSerializer maxItemsInObjectGraph="2147483647" /></FONT>
</behavior>
</serviceBehaviors>
</behaviors>


以下是相关资料:

http://bbs.csdn.net/topics/390322439?page=1#post-393257147

http://www.cnblogs.com/Mainz/archive/2011/09/23/2186284.html

/article/4226550.html

/article/4591859.html

原文地址:http://bbs.silverlightchina.net/forum.php?mod=viewthread&tid=16706

网上有很多网友提问超时的问题,,,也有很多网友回答,,,但是很官方,,,

我也是网上提问的silverlight菜鸟之一,,,这个问题后来算是解决了,,,

在此留个脚印,希望对有同样疑问的人有所帮助。。。

先介绍一下我的开发环境,,,Silverlight 4 + DomainService(WCF RIA,不是WCF)

(网上的回答大多基于WCF的方式,和WCF RIA二者还是有区别的,但这种区别大多被回答者自动忽视)

1、一般解决的方法是去修改OpenTimeout,ReceiveTimeout,SendTimeout,CloseTimeout

Public Sub ChangeWcfSendTimeout(ByVal context As DomainContext, ByVal Timeout As TimeSpan)

Dim channelFactoryProperty As PropertyInfo = context.DomainClient.GetType().GetProperty("ChannelFactory")

If channelFactoryProperty Is Nothing Then

Throw New InvalidOperationException(

"There is no 'ChannelFactory' property on the DomainClient.")

End If

Dim factory As ChannelFactory = CType(channelFactoryProperty.GetValue(context.DomainClient, Nothing), ChannelFactory)

factory.Endpoint.Binding.OpenTimeout = Timeout

factory.Endpoint.Binding.ReceiveTimeout = Timeout

factory.Endpoint.Binding.SendTimeout = Timeout

factory.Endpoint.Binding.CloseTimeout = Timeout

  End Sub

2、还有一种超时问题,上面的方法不能解决。

  应用场景是:SL调用存储过程返回一个Entity,返回的数据量不大,问题在于这个存储过程执行需要时间,必须要修改 TransactionTimeOut

  <serviceBehaviors>

    <serviceTimeouts transactionTimeout="00:06:00"/>

  <serviceBehaviors>

3、相关上面的场景,存储过程执行的时候,也有一个设定超时的属性,在少数情况下也会导致超时

  'Initializes a new FPDB object Inherits ObjectContext using the connection string

  Public Sub New()

MyBase.New("name=FPDBConn", "FPDBConn")

MyBase.ContextOptions.LazyLoadingEnabled = True

Me.CommandTimeout = 360

OnContextCreated()

End Sub

4、还有一种伪超时,因为后来证明,并不是超时问题,而是SL的序列化的size是有限制的

  应用场景:有一个应用依据选择的日期,去数据库读数据,当日期范围不大,返回的数据量比较少时,没有问题。

       当选择的日期范围比较大,返回的数据超过临界值时,就会报Not found错误

<behavior>

<dataContractSerializer maxItemsInObjectGraph="2147483647"/>

</behavior>

4、没有了,如果还有问题可以和我联系,一起探讨

  在此也送上一句官方回答:超时引起的原因有很多种,建议你打开WCF log以及使用fiddler监视网络

原创欢迎转载,请注明作者,并保留此段声明,且在文章页面明显位置给出原文连接
http://www.cnblogs.com/youfan/archive/2011/06/09/2076094.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: