.net WCF主机延迟15秒
我正在使用.NET3.5和WCF开发服务器客户端应用程序。Binding=BasicHttp。 我正在windows 2003服务器sp2中工作并部署该服务 服务器中的服务由控制台应用程序自托管,在我的计算机中一切正常。问题是,当我在应该运行的计算机中部署服务器时,打开serviceHost实例只需要15秒,而这应该是毫秒。我可以接受这一点,但当这个实例收到来自客户机的第一个请求时,响应只需要15秒,每个新客户机都是这样。在第一个请求之后,响应以下请求只需几毫秒 我的电脑没有这个问题,我也试过很多其他的电脑,它也工作得很好。我不可能格式化我正在部署的服务器,所以我需要一些关于特定计算机或配置中可能出现的错误的建议。 这种行为在我想在该机器上托管的任何服务中都会重复,即使是“WCF服务库”模板中的基本示例也是如此,因此为了简单起见,我在解决此问题时正在处理它。 这是我在主机应用程序中使用的app.config。其余的代码就是上面提到的模板之一。 请记住,服务运行良好,是延迟导致服务无法使用 提前谢谢.net WCF主机延迟15秒,.net,wcf,web-services,.net,Wcf,Web Services,我正在使用.NET3.5和WCF开发服务器客户端应用程序。Binding=BasicHttp。 我正在windows 2003服务器sp2中工作并部署该服务 服务器中的服务由控制台应用程序自托管,在我的计算机中一切正常。问题是,当我在应该运行的计算机中部署服务器时,打开serviceHost实例只需要15秒,而这应该是毫秒。我可以接受这一点,但当这个实例收到来自客户机的第一个请求时,响应只需要15秒,每个新客户机都是这样。在第一个请求之后,响应以下请求只需几毫秒 我的电脑没有这个问题,我也试过很
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="WcfServiceLibrary7.Service1" behaviorConfiguration="WcfServiceLibrary7.Service1Behavior">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8732/Design_Time_Addresses/WcfServiceLibrary7/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address ="" binding="wsHttpBinding" contract="WcfServiceLibrary7.IService1">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfServiceLibrary7.Service1Behavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
客户端App.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8732/Design_Time_Addresses/WcfServiceLibrary7/Service1/"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
contract="ServiceReference1.IService1" name="WSHttpBinding_IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
第一次加载ServiceHost总是需要很长时间。一些原因:
- 加载组件
- 开放港口
- JITting代码
- 执行各种反射操作
更新
查看客户端配置后,似乎作为消息与
clientCredentialType=“Windows”
一起使用的安全机制将调用域控制器,域控制器可能会超时一种预感——仅此而已——解析某个网络名称时,某个地方出现DNS超时。做
ping localhost
还要给你15秒的延迟吗
类似地,可能有人试图对传入主机名执行反向DNS查找。您的远程主机是否具有可由服务器解析的名称
您可能还想检查在端口8732上打开连接时是否有防火墙或病毒检查器以某种奇怪的方式拦截HTTP请求 首先,我会在客户端使用fiddler来查看发生了什么。如果需要,您还可以在出现非http低级网络问题时使用netmon 在服务器端,您可以分析、跟踪或记录,以查看在15秒的请求期间,服务器代码花费了多少时间 这些至少会告诉你从哪里开始
如果是针对每个客户端的新请求,您应该查看身份验证、DNS名称解析和其他网络配置。另一个很好的实验是,在用户15秒的请求之后,回收服务器应用程序并再次发出请求。又是15秒?如果不是,则可能是网络,如果是,则是app/config中的某个内容。当我发现它没有安装.NET 3.5的service pack 1时,问题就解决了。在电脑里我遇到了问题。一旦我安装了它,一切都开始正常运行,没有延迟 谢谢大家的建议! 顺致敬意,
Nacho是的,但这应该是一个一次性问题——如果它发生在每个服务请求上,那么很可能是其他问题。它发生在每个与服务连接的新客户端上,并且只发生在该特定计算机的第一次调用中。在另一台计算机上,服务运行正常。这就是我的要命,所以每一个新客户?当一个新客户机连接而其他客户机连接时也是这样吗?它的空闲时间设置是什么?在创建新servicehost时,客户端和服务器中的空闲时间总是正好15秒。我确信这是某种超时,但我不知道如何在WCF中除了诊断之外跟踪它。不,我的意思是将客户端绑定配置也放在那里。当您在15秒等待中等待7秒时,暂停正在运行的进程,并查看进程调用堆栈在哪里等待。由于这是在不是您的开发机器的pc上运行的(刚刚看到),您可以使用task manager进行进程转储,然后在pc上打开生成的dmp文件以查看进程正在做什么Drats,刚刚看到您在net3.5上,这意味着您无法在visual studio中查看dmp文件。尽管如此,您仍可以使用windbg检查调用堆栈,或在.net4中运行它作为一次性调试目的。我正在与服务器中的诊断和进程堆栈进行交易活动。如果我在另一台计算机上安装该服务,它可以正常运行。我ping localhost,它会在不到1毫秒的时间内做出响应。我现在会检查防病毒软件。防病毒软件关闭了,防火墙关闭了,还有什么吗?我说过这只是一种预感!我认为这与网络有关,因为app.config中的任何配置都有相同的功能。最大的问题是什么?