ASMX Web 服务较慢的第一个请求 [英] ASMX Web Service slow first request

查看:25
本文介绍了ASMX Web 服务较慢的第一个请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个 IIS 应用程序中运行了一堆 .NET Web 服务.这些 Web 服务由另一个 IIS 应用程序(前端)使用.第一次调用很慢,大约 5 到 10 秒.之后只是几毫秒.第一次调用被认为是性能问题.

I have a bunch of .NET Webservices running in one IIS Application. These webservices are consumed by another IIS Application (frontend). The first call is pretty slow, about 5 to 10 seconds. After that it’s just milliseconds. The first call is considered a performance problem.

我们尝试了一个调用所有这些网络服务的应用程序,但这显然没有解决任何问题.因此,问题不是默认的应用程序回收.我创建了一个应用程序,它只是多次初始化服务并测量创建一个实例所需的时间.在运行这个应用程序之前,我确保我的 webservice 应用程序已启动/回收,然后我运行该应用程序.第一次初始化需要 2 到 4 秒,所有其他初始化只需几毫秒.

We’ve tried an application that calls all these webservices but this obviously doesn’t solve anything. So it's not the default Application Recycle that is the problem. I've created an application that just initializes the service several times and measures the time it takes to create one instance. Before running this application I ensure that my webservice application is started / recycled, then I run the application. The first initialization takes between 2 to 4 seconds, all others is just milliseconds.

另一个想法是,我们在 Frontend 应用程序中创建一个页面来启动所有 Web 服务,并在任何用户进入之前调用此页面.我不认为这是一个优雅的解决方案,我还能尝试什么?

Another thought is that we create a page in the Frontend application that initiates all the webservices and that we call this page before any users are in. I don’t consider this as an elegant solution, what else could I try?

推荐答案

客户端第一次调用 webservice 时遇到的延迟是由于默认情况下需要 webservice 的 XmlSerializers dll编译.这导致初始呼叫的 2-4 秒.当然,当 webservice 应用程序已经在运行时就是这种情况,如果不是,你会有一个回收.在这种情况下,其他答案可能会有所帮助.

The delay that is experienced when a client is calling a webservice for the first time is caused by the fact that by default a XmlSerializers dll for the webservice needs to be compiled. This is causing the 2-4 seconds for the initial call. Of course this is the case when the webservice application is already running, if it's not you would have a recycle. In which case the other answers could help.

为了加速初始调用,您可以在编译时创建 XmlSerializers dll.您可以通过将项目构建生成序列化程序集"设置为开启来实现此目的.这会生成一个包含 Web 服务信息的 MyApplication.XmlSerializers.dll.现在初始调用下降到 300 毫秒,大概是 dll 的加载.0 毫秒后所有调用都在那里.

To speed up the initial call you can create the XmlSerializers dll at compile time. You can do this by setting your project build 'Generate serialization assembly' to on. This generates an MyApplication.XmlSerializers.dll containing the webservice information. Now the initial call dropped to 300 ms, presumably the loading of the dll. All calls there after take 0 ms.

在 Visual Studio 中右键单击您的项目并选择属性".转到构建"选项卡.在输出"部分中有一个选项生成序列化程序集".如果将该值更改为On",则将在编译期间生成序列化程序集.

In Visual Studio right click on your project and choose 'Properties'. Go to the 'Build' Tab. There you have an option 'Generate Serialization assembly' in the 'Output' section. If you change the value to 'On' the serialization assembly will be generated during compile time.

这篇关于ASMX Web 服务较慢的第一个请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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