MEX客户端行为因机器而异

时间:2012-12-07 12:13:20

标签: wcf wcf-client

我在从多台不同计算机访问的服务器上运行.NET WCF Web服务。为了测试我的连接,我有一个PowerShell脚本,用于构建代理,连接到Web服务,发送消息和断开连接。构建代理的代码来自:http://www.ilovesharepoint.com/2008/12/call-wcf-services-with-powershell.html

我有一个批处理文件,运行多次迭代的脚本(500次),我看到不同的行为,具体取决于我运行测试脚本的客户端计算机:

  • 计算机A:成功运行脚本,没有任何失败。完成所有500次迭代大约需要15分钟。
  • 计算机B:迭代失败率约为3%-4%。完成所有500次迭代需要超过1小时。失败发生在每3-5分钟一次。

当脚本失败时,我收到的消息是:

  

使用“0”参数调用“GetMetadata”的异常:“元数据   包含无法解析的引用:'https://   服务器:8733 / WSEngineService /?WSDL'。“在D:\ CLIENT \ proxyTest.ps1:32   焦炭:41   + $ metadataSet = $ mexClient.GetMetadata<<<< ()       + CategoryInfo:NotSpecified:(:) [],ParentContainsErrorRecordException       + FullyQualifiedErrorId:DotNetMethodException

异常的堆栈跟踪是:

  

在   System.Management.Automation.DotNetAdapter.AuxiliaryMethodInvoke(对象   target,Object []参数,MethodInforma tion方法信息,   Object [] originalArguments)at   System.Management.Automation.DotNetAdapter.MethodInvokeDotNet(字符串   methodName,Object target,MethodInformation [] methodInformation,   Object [] arguments)at   System.Management.Automation.Adapter.BaseMethodInvoke(PSMethod方法,   Object [] arguments)at   System.Management.Automation.ParserOps.CallMethod(令牌令牌,对象   target,String methodName,Object [] paramAr ray,Boolean callStatic,   对象valueToSet)at   System.Management.Automation.MethodCallNode.InvokeMethod(对象   target,Object [] arguments,Object value)at   System.Management.Automation.MethodCallNode.Execute(数组输入,管道   outputPipe,ExecutionContext context)at   System.Management.Automation.AssignmentStatementNode.Execute(阵列   input,Pipe outputPipe,ExecutionContext conte xt)at   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   
}

我的网络服务配置如下:

    <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}

我不知道为什么脚本偶尔会在COMPUTER B上失败,但在COMPUTER A上永远不会失败。不幸的是,COMPUTER B是一个加载驱动程序,用于对Web服务运行性能测试,并且失败阻碍了我有能力进行测试。我不能使用COMPUTER A进行测试,原因我不想进入这里。我可以在两台计算机之间看到的唯一区别是COMPUTER A是Windows 7 Professional工作站,COMPUTER B是Windows 2008 R2服务器。两者都安装了相同版本的.NET框架和PowerShell。

有没有人对COMPUTER B为何无法获取我的网络服务的元数据有任何想法?

1 个答案:

答案 0 :(得分:1)

我想我找到了原因并找到了解决办法。

计算机B有6个网络适配器,一个连接到我们的公司网络,一个被禁用,另外四个已启用,每个都有自己的IP地址,并连接到“未知网络”。除了连接到我们网络的1个适配器外,我禁用了所有,而COMPUTER B现在的行为类似于COMPUTER A.