简体   繁体   English

Windows Service托管的WCF终结点存在问题

[英]Problems with WCF endpoints hosted from Windows Service

I have a managed Windows Service that hosts a couple of WCF endpoints. 我有一个托管Windows服务,该服务承载几个WCF端点。 The service is set to start automatically when the PC is restarted. 重新启动PC时,该服务设置为自动启动。 On reboot I find that this line of code: 重新启动后,我发现以下代码行:

ServiceHost wcfHost1 = new ServiceHost(typeof(WCFHost1));

in the OnStart() method of the service takes somewhere between 15 - 20 seconds to execute. 该服务的OnStart()方法中的代码执行需要15到20秒之间的时间。 Actually I have two such statements but the second one executes in a flash. 实际上,我有两个这样的语句,但是第二个语句在瞬间执行。 It is the first one that takes so long. 这是第一个花费这么长时间的时间。 Does anyone know what could be causing the bottleneck? 有谁知道造成瓶颈的原因是什么? Because of this, sometimes the call exceeds 30 seconds and as a result the SCM thinks my service timed out while trying to initialize itself. 因此,有时呼叫时间超过30秒,因此SCM认为我的服务在尝试初始化自身时超时。 Now, I know its easy for me to just spin off a thread to do this and return from OnStart() right away but I'd like to know what could cause this delay. 现在,我知道很容易剥离线程来执行此操作并立即从OnStart()返回,但是我想知道是什么原因导致此延迟。

This happens only when the service starts up on PC reboot. 当服务在PC重新启动时启动时, 才会发生这种情况。 If the PC is up and running, the service starts & stops in less than a second. 如果PC已启动并正在运行,则服务会在不到一秒钟的时间内启动和停止。

This might provide more help. 可能会提供更多帮助。 Basically, I think you need to figure out what dependencies you have and add them to your service, so they start before yours. 基本上,我认为您需要弄清楚所拥有的依赖项并将它们添加到服务中,以便它们在您的依赖项之前开始。

This is just a shot in the dark, but could it be that the .net framework hasn't loaded yet. 这只是黑暗中的一枪,但可能是.net框架尚未加载。 Perhaps, you can try to set the Automatic Start to a Delayed Automatic Start, which will allow the .net framework and other windows services time to start. 也许,您可以尝试将“自动启动”设置为“延迟的自动启动”,这将使.net框架和其他Windows服务有时间启动。

Also, when a .net application starts up, it is compiled with the Just-In-Time compiler. 另外,.net应用程序启动时,将使用即时编译器进行编译。 This could be waiting for .net to compile it. 这可能正在等待.net进行编译。

Lastly, depending on the type of WCF Instance you are using, you could have an issue with the constructor taking awhile to initialize. 最后,根据您使用的WCF实例的类型,构造器可能需要花一些时间才能初始化。

Hope this helps. 希望这可以帮助。

I have had problems with a Windows Service that took a long time to start. 我花了很长时间才能启动Windows服务,但遇到了问题。 I found out that it was because of signed assemblies I used (Enterprise Library). 我发现这是因为我使用了已签名的程序集(企业库)。 .NET was trying to verify the Authenticode signature when the assembly is loaded (maybe your constuctor is using a type for the first time which causes loading that assembly). .NET尝试在加载程序集时验证Authenticode签名(也许您的构造函数首次使用类型导致加载该程序集)。 Just try adding the following to your app.config. 只需尝试将以下内容添加到您的app.config中即可。 When it doesn't work you have another problem. 当它不起作用时,您还有另一个问题。

<configuration>
    <runtime>
        <generatePublisherEvidence enabled="false"/>
    </runtime>
</configuration>

You can also find some extra information here: http://support.microsoft.com/kb/936707 and Why is my .Net app contacting Verisign? 您还可以在这里找到一些其他信息: http : //support.microsoft.com/kb/936707为什么我的.Net应用程序会与Verisign联系?

There is no problem with your WCF service. 您的WCF服务没有问题。 The best way to resolve your issue is to create a dummy operation that the client must call before anything else. 解决问题的最佳方法是创建一个虚拟操作,客户端必须先调用该虚拟操作。 This will force your client to do its handshake on your service prior to your real transaction. 这将迫使您的客户在进行实际交易之前先对您的服务进行握手。 I actually used dummy operation to call my service every now and then to see if it is still alive. 实际上,我实际上使用了虚拟操作来不时调用我的服务,以查看它是否仍然有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM