如何加快WCF客户端的启动性能

发布于 2024-12-03 05:48:27 字数 541 浏览 3 评论 0原文

我已经使用 basicHttpBinding 绑定实现了一个简单的独立 WCF 服务。 我创建了一个客户端并使用“添加服务引用”生成了客户端存根代码。 客户端第一次调用服务时,服务器至少需要 15 秒才能看到请求。通过阅读这个似乎是由于序列化代码的 JIT 生成所致。 此处 的描述预先生成代码

svcutil.exe /t:xmlSerializer <assemblyPath>

我尝试按照 已编译客户端 exe 但代码却出现以下错误:程序集中没有服务协定具有使用 XmlSerializerOperationBehavior 的操作。

I have implemented a simple standalone WCF service with a basicHttpBinding binding.
I created a client and generated the client stub code by using Add Service Reference.
The first time the client call the service it takes at least 15 seconds before the server sees the request. From reading this it seems that it is due to JIT generation of serialization code.
I tried to pre-generate the code as described here using

svcutil.exe /t:xmlSerializer <assemblyPath>

on my complied client exe but code but got the following error: No service contract in the assembly has an operation with XmlSerializerOperationBehavior.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

裸钻 2024-12-10 05:48:27

首先,您应该注意,如果您使用预编译代码,您将损失性能,因为预编译代码不使用任何特定于平台的代码,它只是编译“正常”代码。

另一方面,JIT 在第一次编译(用于创建代理类)时确实会受到一些性能影响,但它在以后的请求中确实效果更好。

因此,我建议您检查服务和客户端的初始化代码 - 也许您可以对其进行优化(15 秒意味着您正在从各种程序集创建大量对象)。

尝试使用一些惰性类

First of all, you should note, that if you are using precompiled code, you will lose performance, as precompiled code doesn't use any platform-specific, it just compiles a "normal" code.

On other hand, JIT really get some performance hit at the first-time compilation (for the proxy-class creation), but it really works better at futher requests.

So I suggest you to check the initialization code for your service and client - may be, you can optimize it (15 seconds means that you are creating much number of objects from various assemblies).

Try to use some Lazy classes

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文