I was trying to create WCF client following instructions from here:
Execute a one-way wcf service operation from powershell
Here’s the piece of code that is breaking
$contractDescription = [System.ServiceModel.Description.ContractDescription]::GetContract([Iinterface])
$serviceEndpoint = New-Object System.ServiceModel.Description.ServiceEndpoint $contractDescription
$channelFactory = New-Object "System.ServiceModel.ChannelFactory``1[Iinterface]" $serviceEndpoint
My interface is stored in a separate assembly that I have Add-Typed. What is puzzling me is that this
$contractDescription = [System.ServiceModel.Description.ContractDescription]::GetContract([Iinterface])
is working just fine, but
$channelFactory = New-Object "System.ServiceModel.ChannelFactory``1[Iinterface]" $serviceEndpoint
is failing with:
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
Did I mess up syntax around generics?
Thanks.
The workaround is to use