【发布时间】:2011-12-28 13:58:58
【问题描述】:
我正在使用 .NET 3.5 和 WCF 来开发服务器-客户端应用程序。绑定=基本的Http。 我正在 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>
【问题讨论】:
-
当您进入 15 秒等待的 7 秒时,暂停正在运行的进程并查看进程调用堆栈在哪里等待。由于这是在不是您的开发机器的 PC 上运行(刚刚看到),您可以改为使用任务管理器进行进程转储,然后在您的 PC 上打开生成的 dmp 文件以查看进程在做什么
-
Drats,刚刚看到您在 net3.5 上,这意味着您无法在 Visual Studio 中查看 dmp 文件。尽管如此,您可以使用 windbg 检查调用堆栈或在.net4 中一次性运行它以进行调试
-
我正在使用服务器中的诊断和进程堆栈来交易活动。如果我在另一台计算机上安装该服务,它运行得很好。
标签: .net wcf web-services