我正在使用.NET 3.5和WCF开发服务器-客户端应用程序。绑定= BasicHttp。
我正在Windows 2003 Server SP2中工作和部署该服务。
服务器中的服务由控制台应用程序自行托管,而在我的计算机中,一切正常。事实是,当我将服务器部署到计算机中时,它应该运行,打开serviceHost实例大约需要15秒钟,而这应该是毫秒。我可以忍受,但是当此实例从客户端接收到第一个请求时,它需要花费恰好15秒的时间来响应,并且对于每个新客户端来说都是这样。在第一个请求之后,只需几毫秒即可响应以下内容。
我的计算机没有这个问题,我已经尝试了许多其他方法,并且工作正常。我无法格式化要在其中部署的服务器,因此我需要一些有关该特定计算机或配置中可能存在问题的建议。
对于要在该计算机上托管的任何服务,甚至是“ WCF服务库”模板中的基本示例,都将重复这种行为,因此,为简单起见,我在解决此问题的同时对其进行了处理。
这是我在主机应用程序中使用的app.config。其余代码正是上述模板之一。
请记住,该服务运行良好,是导致该服务无法使用的延迟。
提前致谢 !
<?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>
最佳答案
我将从在客户端使用小提琴手开始,看看发生了什么。如果有非HTTP较低级别的网络问题,如果需要,您也可以进行netmon。
在服务器端,您可以分析,跟踪或记录以查看在15秒钟的请求期间,服务器代码花费了多少时间。
这些至少会告诉您从哪里开始。
如果是针对每个客户端的新请求,则应查看身份验证,DNS名称解析和其他网络配置。另一个好的实验是在请求用户15秒后,回收服务器应用并再次发出请求。再过15秒?如果不是,则可能是网络,如果是,则是app / config中的某些内容。