0

我有一个与 .NET 4 WCF Web 服务通信的网站。该 WCF 服务连接到远程服务器上的 Dynamics GP Web 服务。两种 Web 服务都是自托管的(无 IIS)。

首次呼叫 GP 大约需要 12 秒才能完成!之后立即调用(即使在另一个 WCF 请求中)大约 100 毫秒,但如果我在两次调用之间等待一两分钟,它将再次需要 10 秒......

问题的原因可能是什么,我该如何解决?

我已经使用 SvcUtil 和 VS 2010 Add Service Reference 生成了一个代理,但两者都遇到了同样的问题。Dynamics GP代理文件很大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>
4

1 回答 1

2

自我回答

对于社区,这是我发现的(但我无法解释原因,所以不要问!;))

在客户端的 app.config 中,useDefaultWebProxy="true"应该设置为false... 这使得一个非常简单的Hello World Web 服务在第一次调用时从 7 秒传递到 ~100 毫秒。

在客户端的 app.config 中,完全删除该identity > userPrincipalName部分会导致第一个 WCF 调用从 > 10 秒变为 ~1 秒!

于 2011-11-21T15:15:14.870 回答