ASMX Web服务慢的第一个请求第一个、ASMX、Web

2023-09-02 10:22:34 作者:人不嘚瑟枉少年

我有一个IIS应用程序运行一堆.NET Web服务的。这些Web服务被其他IIS应用程序(前端)消耗。第一呼叫是pretty的速度慢,约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.

我们已经尝试调用所有这些Web服务,但这显然并没有解决任何问题的应用程序。因此,这不是默认的应用程序回收这就是问题所在。我创建了刚刚初始化服务几次,并测量它需要创建一个实例时的应用程序。运行该应用程序,我保证我的web应用程序启动/回收之前,我运行应用程序。 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.

另一个想法是,我们在它启动所有的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?

推荐答案

这是当客户端调用Web服务的第一次经历是由事实,默认情况下XmlSerializers DLL文件的web服务需要被延迟编译。这是造成2-4秒的初始呼叫。当然,这种情况下,当Web服务应用程序已经在运行,如果不是,你将有一个循环。在这种情况下,其他的答案可能会有所帮助。

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 presumably加载。所有来电后,有拿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中右键单击您的项目,并选择属性。转到构建标签。有你有一个选择的输出部分中生成序列化程序集。如果将值更改为打开序列化程序集将在编译时生成的。

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.