我有一个与.NET 4 WCF web服务通信的网站。WCF服务连接到远程服务器上的Dynamics服务。这两个Web服务都是自托管的(没有IIS).
第一次调用GP需要大约12秒才能完成!!在调用之后(即使是在另一个WCF请求中)调用大约是100 10,但是如果我在调用之间等待一两分钟,将再次花费10秒.
问题的起因是什么,我如何解决呢?
我使用SvcUtil和VS 2010生成了一个代理,但两者都遇到了同样的问题。Dynamics代理文件是巨大的3MB,不知道这是否相关。
我运行Wireshark来分析网络流量,而实际的tcp请求应答流似乎还不到一秒钟。在发送请求之前,似乎发生了一些事情,占用了10秒时间。
下面是使用的代码:
Context context = new Context();
CompanyKey companyKey = new CompanyKey();
companyKey.Id = -1;
context.OrganizationKey = companyKey;
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
_proxy = new DynamicsGPClient();
_proxy.ClientCredentials.Windows.ClientCredential.Domain = Domain;
_proxy.ClientCredentials.Windows.ClientCredential.UserName = Username;
_proxy.ClientCredentials.Windows.ClientCredential.Password = Password;
long openingMs = sw.ElapsedMilliseconds;
CustomerCriteria customerCriteria = new CustomerCriteria();
CustomerSummary[] gpCustomers = _proxy.GetCustomerList(customerCriteria, context);
long fctCallMs = sw.ElapsedMilliseconds;
...
if (_proxy != null && _proxy.State != System.ServiceModel.CommunicationState.Faulted) {
_proxy.Close();
}这里是app.config:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="GPWebService" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8"
useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="2147483647"/>
<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://192.168.x.y:48620/Dynamics/GPService/GPService" binding="wsHttpBinding"
bindingConfiguration="GPWebService"
contract="DynamicsGpService.DynamicsGP" name="GPWebService">
<identity>
<userPrincipalName value="DEV\gpeconnect"/>
</identity>
</endpoint>
</client>
</system.serviceModel>发布于 2011-11-21 15:15:14
自答
对于社区来说,这是我所发现的(但我无法解释原因,所以不要问!;)
在客户端的app.config中,useDefaultWebProxy="true"应该设置为false.这使得一个非常简单的在第一次调用时从7秒传递到大约100 on。
在客户端的app.config中,完全删除identity > userPrincipalName部分会导致第一个WCF调用从>10秒传递到~1秒!
https://stackoverflow.com/questions/8189880
复制相似问题