gpt4 book ai didi

.net - WCF 主机延迟 15 秒

转载 作者:行者123 更新时间:2023-12-05 01:35:59 24 4
gpt4 key购买 nike

我正在使用 .NET 3.5 和 WCF 来开发服务器-客户端应用程序。绑定(bind)=基本Http。
我正在 Windows 2003 服务器 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>

最佳答案

我会首先在客户端使用 fiddler 来看看发生了什么。如果需要,如果存在非 http 较低级别的网络问题,您也可以执行 netmon。

在服务器端,您可以分析、跟踪或记录,以查看在这 15 秒的请求期间,服务器代码花费了多少时间。

这些至少会告诉你从哪里开始。

如果是针对每个客户端的新请求,您应该查看身份验证、DNS 名称解析和其他网络配置。另一个很好的实验是在对用户发出 15 秒的请求后,回收服务器应用程序并再次发出请求。又是 15 秒?如果不是,则可能是网络,如果是,则应用程序/配置中的某些内容。

关于.net - WCF 主机延迟 15 秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8120849/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com