Question

I have a .NET WCF web service running on a server that I access from several different computers. To test my connectivity, I have a PowerShell script that builds a proxy, connects to the web service, sends a message, and disconnects. The code to build the proxy comes from here: http://www.ilovesharepoint.com/2008/12/call-wcf-services-with-powershell.html

I have a batch file that runs multiple iterations of the script (500 times), and I'm seeing different behavior depending on which client computer I run the test script on:

  • COMPUTER A: Successfully runs the script without any failures. It takes about 15 minutes to do all 500 iterations.
  • COMPUTER B: Iterations fail about 3% - 4% of the time. It takes over 1 hour to do all 500 iterations. Failures occur every 3-5 minutes.

When the script fails, the message I'm getting back is:

Exception calling "GetMetadata" with "0" argument(s): "Metadata contains a reference that cannot be resolved: 'https:// SERVER:8733/WSEngineService/?WSDL'." At D:\CLIENT\proxyTest.ps1:32 char:41 + $metadataSet = $mexClient.GetMetadata <<<< () + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : DotNetMethodException

The stack trace for the exception is:

at System.Management.Automation.DotNetAdapter.AuxiliaryMethodInvoke(Object target, Object[] arguments, MethodInforma tion methodInformation, Object[] originalArguments) at System.Management.Automation.DotNetAdapter.MethodInvokeDotNet(String methodName, Object target, MethodInformation [] methodInformation, Object[] arguments) at System.Management.Automation.Adapter.BaseMethodInvoke(PSMethod method, Object[] arguments) at System.Management.Automation.ParserOps.CallMethod(Token token, Object target, String methodName, Object[] paramAr ray, Boolean callStatic, Object valueToSet) at System.Management.Automation.MethodCallNode.InvokeMethod(Object target, Object[] arguments, Object value) at System.Management.Automation.MethodCallNode.Execute(Array input, Pipe outputPipe, ExecutionContext context) at System.Management.Automation.AssignmentStatementNode.Execute(Array input, Pipe outputPipe, ExecutionContext conte xt) at System.Management.Automation.StatementListNode.ExecuteStatement(ParseTreeNode statement, Array input, Pipe output Pipe, ArrayList& resultList, ExecutionContext context)

The MEX Client properties are:

PS D:\CLIENT>>> $mexClient

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

This is the code where the exception is occurring:

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

My web service is configured like this:

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

I'm telling the proxy test script to ignore any SSL warnings:

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

I'm at a loss as to why the script is occasionally failing on COMPUTER B, but never fails on COMPUTER A. Unfortunately, COMPUTER B is a load driver for running performance tests against the web service, and the failures are impeding my ability to conduct a test. I can't use COMPUTER A for the test, for reasons I don't want to get into here. The only difference I can see between the two computers is COMPUTER A is a Windows 7 Professional workstation and COMPUTER B is a Windows 2008 R2 server. Both have the same versions of .NET framework and PowerShell installed.

Does anyone have any ideas on why COMPUTER B fails trying to get the metadata for my web service?

Was it helpful?

Solution

I think I found the cause and a cure.

COMPUTER B has 6 network adapters, one connected to our corporate network, one disabled, and the other 4 enabled, each with its own IP address, and connected to an "Unknown Network". I disabled all but the 1 adapter connected to our network, and COMPUTER B is now behaving like COMPUTER A.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top