Silverlight/WCF服务在第一次调用时经历非常缓慢的反序列化 [英] Silverlight/WCF service experiencing very slow deserializing on first call

查看:83
本文介绍了Silverlight/WCF服务在第一次调用时经历非常缓慢的反序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用Google搜索并阅读了所有类似的帖子,而答案却不存在!

我正在将Silverlight 5与启用了Silverlight的wcf服务一起使用,但是尝试了silverlight 4和只是一个具有相同结果的常规Windows窗体项目.

在我的每个派生类中,使用基类上的[knowntype]属性进行的所有标准默认设置.我将返回List< baseclass>由所有派生类组成.

我有很多派生类(200),这似乎是个问题.我的服务快速返回了我的请求,但是代理需要很长时间(10)秒来反序列化消息.增加不希望的类(400+)的数量将延迟增加到60秒以上.只有在第一次调用时才会如此,因为随后的调用会快速反序列化(不到1秒).显然,wcf代理必须在第一个调用上执行一些操作以反序列化数据,并仅在后续调用中重用它.重新加载/刷新网页会重新开始整个过程​​,而在第一次调用时会出现明显的延迟.

我已经测试过使用xmlserializer而不是默认的datacontractserializer,并且在反序列化方面确实获得了速度上的好处,但是初始延迟仍然没有那么大(但仍然太多).

WCF应该是旗舰企业解决方案,但到目前为止对我来说很臭!如果无法解决此问题,可能必须去远程处理.

有人知道延迟的原因吗,有人知道如何补偿吗?

我已经读到在Windows窗体中使用xmlserializer时,第一次调用很慢,因为它必须在运行时构建程序集以反序列化数据-我怀疑这里的情况相同. svcutil.exe可用于提前生成程序集以处理反序列化并补偿首次调用延迟时间-Silverlight使用了不具有该功能的slsvcutil.exe.尝试使用常规svcutil会导致错误,因为Silverlight使用常规.Net的不同程序集.

I have googled and read all similar posts and the answers are not there!

I am using silverlight 5 with a silverlight enabled wcf service, but have tried silverlight 4 and just a regular windows form project with the same results.

All standard default settings using the [knowntype]attribute on the base class for each of my derived classes. I am returning a List<baseclass> consisting of all derived classes.

I have a large number of derived classes (200)which seems to be the issue. My service returns my request quickly, but the proxy takes a long time (10) seconds to deserialize the message. Increasing the number of deirved classes (400+)increases the delay to 60 seconds+. This is only the case on the first call as subsequent calls are deserialized quickly (under 1 second). Apparently the wcf proxy has to do something on the first call to deserialize the data and just reuses it on the subsequent calls. Reloading/refreshing the web page starts the process all over with a significant delay on the first call again.

I have tested it to using the xmlserializer instead of the default datacontractserializer and I do gain a speed bonus on the deserialization, but the initial delay is still there just not as great (but still too much).

WCF is supposed to be a flagship enterprise solution, but so far it stinks for me! I might have to go to remoting, etc if I can''t get this resolved.

Does anyone know why the delay is there and does anyone know how to compensate for it?

I have read that with using xmlserializer in windows forms that the first call is slow as it has to build an assembly at runtime to deserialize the data - I suspect the same situation here. svcutil.exe can be used to generate an assembly ahead of time to handle the deserialization and compensate for a first call delay time - silverlight uses slsvcutil.exe which does not have that ability. trying to use regular svcutil results in errors as the silverlight uses different assemblies that regular .Net.

推荐答案

该延迟是由于JIT编译和优化了反序列化代码而引起的.一旦完成,就完全没有时间了.您可以尝试使用JIT设置,看看是否有帮助.

您还可以重新设计数据,以便它不会创建太多不同的类型.
The delay is because of JIT compiling and optimizing your deserialization code. Once it is done it takes no time at all. You may try to play with JIT settings and see if it helps.

You could also redesign your Data so it would not create so many different types.


我不知道是什么原因导致了该错误,但逻辑上这是线程问题.我确实找到了解决方法.我没有使用DataContractSerializer分解对象图并将其重新放在一起,而是使用了另一个序列化器,如Mike Talbot制造的SilverlightSerializer.他的串行器在将对象通过DCS发送之前将其转换为字节数组,然后由其反序列化器对其进行重建.对于包含约5000个对象和300个派生类的50K图形,我的延迟从30-60秒的延迟降低到大约2秒.也不用他的序列化器声明已知类型-您的代码更简洁.
I have no clue what causes this bug but it would seem logical that it is a threading issue. I did find a work around. Instead of using DataContractSerializer to take apart an object graph and put it back together again I used another serializer like the SilverlightSerializer made by Mike Talbot. His serializer converts your object into a byte array before it is sent through the DCS and then his deserializer rebuilds it. My delays went from 30-60 second delays down to about 2 seconds for a 50K graph consisting of about 5000 objects and 300 derived classes. No need to declare knowntypes with his serializer either - your code is much cleaner.


这篇关于Silverlight/WCF服务在第一次调用时经历非常缓慢的反序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆