2011-11-18 98 views
0

我有一個與.NET 4 WCF Web服務進行通信的網站。該WCF服務連接到遠程服務器上的Dynamics GP Web服務。這兩個Web服務都是自託管的(沒有IIS)。首次調用Dynamics GP 2010 Web服務需要10多秒

GP的第一個電話需要大約12秒才能完成!呼籲立即後(即使在另一個WCF請求)是100毫秒左右,但如果我等待調用之間一兩分鐘,這將需要10再次數秒

可能是什麼問題的原因,如何我可以解決它嗎?

我已經使用SvcUtil和VS 2010添加服務引用生成了一個代理,但兩者都有同樣的問題。動態GP代理文件是巨大的3MB,不知道這是相關的。

我運行Wireshark來分析網絡流量,實際的tcp request-reply流似乎不到一秒鐘。在請求發送之前似乎有一些事情要花費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> 
+0

我對Dynamics的所有知識都不瞭解,但這聽起來像是第一次啓動Dynamics服務的IIS應用程序池。這可能需要一些時間。假設是這種情況,您可能需要檢查應用程序池上的超時設置。 IIS應用程序池的默認超時時間爲20分鐘,因此增加應減少必須經過此啓動延遲的次數。 –

+0

感謝Chris,但我不這麼認爲,Web服務(Dynamics和我自己)都是「自我託管」的。而且,遠低於20分鐘的標準,長時間的延遲迴來了...... – dstj

回答

2

自答案

爲界,這裏是我已經發現了(但我無法解釋爲什麼,所以不要問!))

在客戶端的app.config中,useDefaultWebProxy="true"應該設置爲false ......這樣做很簡單Hello World Web服務在第一次調用時從7秒過渡到〜100ms。

在客戶端的app.config中,完全刪除identity > userPrincipalName部分導致第一個WCF調用從大於10秒傳遞到大約1秒!