header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Calling a Templated Method
Last Post 16 Jul 2010 12:09 PM by 0ptikGhost. 2 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Resolved
0ptikGhostUser is Offline
Basic Member
Basic Member
Posts:296
Avatar

--
16 Jul 2010 11:39 AM

    I'm trying to call the following method (from a WSE service proxy):

    Name MemberType Definition ---- ---------- ---------- SetClientCredential Method System.Void SetClientCredential[TSecurityToken](TSecurityToken clientToken)

    I keep getting the following error:

    Exception calling "SetClientCredential" with "1" argument(s): "Value cannot be null. Parameter name: key" At E:\Path\To\Script.ps1:70 char:33 + $service.SetClientCredential <<<< ($userToken) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvoke

    I have verified $userToken is not null. The exception stack trace suggests to me that PowerShell is looking for the SetClientCredential method and not finding it:

    at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument) at System.Collections.Generic.Dictionary`2.FindEntry(TKey key) at System.Collections.Generic.Dictionary`2.ContainsKey(TKey key) at System.Management.Automation.LanguagePrimitives.TypeConverterPossiblyExists(Type type) at System.Management.Automation.LanguagePrimitives.FigureConversion(Type fromType, Type toType) at System.Management.Automation.LanguagePrimitives.ConvertTo(Object valueToConvert, Type resultType, Boolean recursi on, IFormatProvider formatProvider, TypeTable backupTypeTable) at System.Management.Automation.Adapter.PropertySetAndMethodArgumentConvertTo(Object valueToConvert, Type resultType , IFormatProvider formatProvider) at System.Management.Automation.Adapter.MethodArgumentConvertTo(Object valueToConvert, Boolean isParameterByRef, Int 32 parameterIndex, Type resultType, IFormatProvider formatProvider) at System.Management.Automation.Adapter.SetNewArgument(String methodName, Object[] arguments, Object[] newArguments, ParameterInformation parameter, Int32 index) at System.Management.Automation.Adapter.GetMethodArgumentsBase(String methodName, ParameterInformation[] parameters, Object[] arguments, Boolean expandParamsOnBest) at System.Management.Automation.DotNetAdapter.MethodInvokeDotNet(String methodName, Object target, MethodInformation [] methodInformation, Object[] arguments) at System.Management.Automation.Adapter.BaseMethodInvoke(PSMethod method, Object[] arguments)

    Clearly, the problem is that I'm trying to call a templated method and I'm not invoking it properly. Does anybody know how to call a templated method?

    0ptikGhostUser is Offline
    Basic Member
    Basic Member
    Posts:296
    Avatar

    --
    16 Jul 2010 12:00 PM

    I tried calling the method via naive reflection:

    $serviceType = [ServiceTypeName] $methodInfo = $serviceType.GetMethod('SetClientCredential') $null = $methodInfo.Invoke($service, @($userToken))

    And I got this error:

    Exception calling "Invoke" with "2" argument(s): "Late bound operations cannot be performed on types or methods for whi ch ContainsGenericParameters is true." At E:\Path\To\Script.ps1:72 char:31 + $null = $methodInfo.Invoke <<<< ($service, @($userToken)) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException

    I think this confirms what I thought was happening. Now I just need to learn how to call methods with generic parameters via reflection.

    0ptikGhostUser is Offline
    Basic Member
    Basic Member
    Posts:296
    Avatar

    --
    16 Jul 2010 12:09 PM
    • Accepted Answer

    I solved my problem. Here's how I had invoke the method:

    $serviceType = [ServiceTypeName] $openMethod = $serviceType.GetMethod('SetClientCredential') $closedMethod = $openMethod.MakeGenericMethod($userToken.GetType()) [Microsoft.Web.Services3.Security.Tokens.UsernameToken[]]$parameters = @($userToken) $null = $closedMethod.Invoke($service, $parameters)

    I had to specify the type for the $parameters array because I got an error telling me that "Object of type 'System.Management.Automation.PSObject' cannot be converted to type 'Microsoft.Web.Services3.Security.Tokens.UsernameToken'."

    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer