gpt4 book ai didi

powershell - 来自其他程序集的泛型

转载 作者:行者123 更新时间:2023-12-03 00:20:45 27 4
gpt4 key购买 nike

我试图按照此处的说明创建WCF客户端:
Execute a one-way wcf service operation from powershell

这是断断续续的代码

$contractDescription = [System.ServiceModel.Description.ContractDescription]::GetContract([Iinterface])
$serviceEndpoint = New-Object System.ServiceModel.Description.ServiceEndpoint $contractDescription
$channelFactory = New-Object "System.ServiceModel.ChannelFactory``1[Iinterface]" $serviceEndpoint

我的界面存储在我具有Add-Typed的单独程序集中。让我感到困惑的是
    $contractDescription = [System.ServiceModel.Description.ContractDescription]::GetContract([Iinterface])

工作正常,但是
    $channelFactory = New-Object "System.ServiceModel.ChannelFactory``1[Iinterface]" $serviceEndpoint

失败:

New-Object : Cannot find type [System.ServiceModel.ChannelFactory`1[Iinterface]]: make sure the assembly containing this type is loaded. At C:\Users\amarchuk\AppData\Local\Temp\1\bbc2b1ab-fe3a-4982-a561-2bfe926b7362.ps1:29 char:29 + $channelFactory = New-Object <<<< "System.ServiceModel.ChannelFactory``1[Iinterface]" $serviceEndpoint + CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand



我是否弄乱了泛型的语法?
谢谢。

最佳答案

试试这个:

$channelFactory = New-Object 'System.ServiceModel.ChannelFactory``1'([Iinterface])

编辑:

要么
$channelFactory = New-Object -typename 'System.ServiceModel.ChannelFactory``1'([Iinterface])

但我可以测试。

关于powershell - 来自其他程序集的泛型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8227222/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com