2012-12-07 16 views
1

我有一個.NET WCF Web服務運行在服務器上,我從幾臺不同的計算機上訪問。爲了測試我的連接性,我有一個PowerShell腳本,用於構建代理,連接到Web服務,發送消息並斷開連接。建立代理的代碼來自這裏:http://www.ilovesharepoint.com/2008/12/call-wcf-services-with-powershell.htmlMEX客戶端行爲跨機器不同

我有一個批處理文件運行腳本的多次迭代(500次),我看到不同的行爲取決於我運行測試腳本的客戶端計算機:

  • 計算機A:成功運行腳本時未出現任何故障。完成500次迭代需要大約15分鐘的時間。計算機B:迭代失敗約3%-4%的時間。需要超過1小時做所有500次迭代。每3-5分鐘發生一次故障。

當腳本失敗,消息我得到的回覆是:

異常調用「的getMetaData」和「0」的說法(S):「元數據 包含無法解析的引用:'https:// SERVER:8733/WSEngineService /?WSDL'。「在d:\ CLIENT \ proxyTest.ps1:32 字符:41 + $ metadataSet = $ mexClient.GetMetadata < < < <() + CategoryInfo:NotSpecified:(:) [],ParentContainsErrorRecordException + FullyQualifiedErrorId:DotNetMethodException

爲異常堆棧跟蹤爲:

在 System.Management.Automation.DotNetAdapter.AuxiliaryMethodInvoke(對象 目標,對象[] ARG uments,MethodInforma灰methodInformation, 對象[] originalArguments)在 System.Management.Automation.DotNetAdapter.MethodInvokeDotNet(字符串 方法名,對象目標,MethodInformation [] methodInformation, 對象[]參數)在 System.Management.Automation。 Adapter.BaseMethodInvoke(PSMethod方法, 對象[]參數)在 System.Management.Automation.ParserOps.CallMethod在 (令牌標記,對象 目標,字符串方法名,對象[] paramAr射線,布爾callStatic, 對象valueToSet) System.Management.Automation.MethodCallNode.InvokeMethod(對象 target,Object [] arguments,Object value)at System.Managemen t.Automation.MethodCallNode.Execute(陣列輸入端,管 outputPipe,的ExecutionContext上下文)在 System.Management.Automation.AssignmentStatementNode.Execute(陣列 輸入,管outputPipe,的ExecutionContext康特XT)在 System.Management.Automation.StatementListNode 。ExecuteStatement(ParseTreeNode 語句,陣列輸入,管輸出管,ArrayList的& resultList, 的ExecutionContext上下文)

的MEX客戶端屬性是:

PS D:\CLIENT>>> $mexClient 

SoapCredentials   : System.ServiceModel.Description.ClientCredentials 
HttpCredentials   : 
OperationTimeout   : 00:01:00 
MaximumResolvedReferences : 2147483647 
ResolveMetadataReferences : True 

這是異常發生的代碼:

# get metadata of a service 
function global:Get-WsdlImporter($wsdlUrl=$(throw "parameter -wsdlUrl is missing"), $httpGet) 
{ 
     if($httpGet -eq $true) 
     { 
       $local:mode = [System.ServiceModel.Description.MetadataExchangeClientMode]::HttpGet 
     } 
     else 
     { 
       $local:mode = [System.ServiceModel.Description.MetadataExchangeClientMode]::MetadataExchange 
     } 

     $mexClient = New-Object System.ServiceModel.Description.MetadataExchangeClient((New-Object System.Uri($wsdlUrl)),$mode) 
     $mexClient.MaximumResolvedReferences = [System.Int32]::MaxValue 
     $metadataSet = $mexClient.GetMetadata() # <-- Fails sometimes on COMPUTER B but never on COMPUTER A. 
     $wsdlImporter = New-Object System.ServiceModel.Description.WsdlImporter($metadataSet) 

     return $wsdlImporter 
} 

我的Web服務配置是這樣的:

<behavior name="WsTuBehaviorConfig"> 
     <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" httpsGetBinding="" /> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
     <serviceThrottling maxConcurrentCalls="40" maxConcurrentSessions="40" maxConcurrentInstances="40" /> 
     <serviceCredentials> 
     <clientCertificate> 
      <authentication certificateValidationMode="PeerTrust" /> 
     </clientCertificate> 
     <userNameAuthentication userNamePasswordValidationMode="Custom" membershipProviderName="Ldap" customUserNamePasswordValidatorType="MyProduct.Framework.Security.AuthenticationProvider.UserNamePasswordLdapUserId,MyProduct.Framework.Security.AuthenticationProvider" /> 
     </serviceCredentials> 
     <serviceAuthorization principalPermissionMode="UseAspNetRoles" roleProviderName="LdapOperationProvider" /> 
     <useRequestHeadersForMetadataAddress /> 
    </behavior> 

    <ws2007HttpBinding> 
    <binding name="ws2007HttpTuBindingConfig" maxReceivedMessageSize="2147483647"> 
     <readerQuotas maxDepth="3200" maxStringContentLength="8192" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
     <security mode="Transport"> 
     <transport clientCredentialType="Basic" proxyCredentialType="None" /> 
     <message clientCredentialType="None" negotiateServiceCredential="false" establishSecurityContext="false" /> 
     </security> 
    </binding> 
    </ws2007HttpBinding> 

    <service behaviorConfiguration="WsTuBehaviorConfig" name="MyProduct.BusinessLibrary.Services.WSEngineService"> 
    <endpoint name="WsEngineWs2007HttpEp" address="ws2007HttpEP" binding="ws2007HttpBinding" bindingConfiguration="ws2007HttpTuBindingConfig" behaviorConfiguration="accessDeniedFaultBehaviorConfig" contract="MyProduct.BusinessLibrary.Services.IWSEngineService" /> 
    <endpoint name="mexWSEngineEP" address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" /> 
    <host> 
     <baseAddresses> 
     <add baseAddress="https://SERVER:8733/WSEngineService/" /> 
     </baseAddresses> 
    </host> 
    </service> 

我說的是代理測試腳本忽略任何SSL警告:

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} 

我不知所措,爲什麼腳本未能偶爾在計算機B上,但從來沒有失敗計算機A.不幸的是,COMPUTER B是一個負載驅動程序,用於對Web服務執行性能測試,而這些失敗阻礙了我進行測試的能力。我不能使用計算機A進行測試,因爲我不想在這裏介紹。兩臺計算機之間唯一的區別是COMPUTER A是Windows 7 Professional工作站,COMPUTER B是Windows 2008 R2服務器。兩者都安裝了相同版本的.NET框架和PowerShell。

有沒有人有任何想法爲什麼計算機B未能嘗試獲取我的Web服務的元數據?

回答

1

我想我找到了原因和治療方法。

COMPUTER B有6個網絡適配器,一個連接到我們的公司網絡,一個禁用,另外4個啓用,每個都有自己的IP地址,並連接到「未知網絡」。除了連接到我們網絡的1個適配器外,我禁用了所有的功能,並且計算機B現在表現得像計算機A.