这更像是一种解决方法,但也许它对您有用。不使用 cmdlet,而是创建一个 C# 或 VB.NET 项目,添加 WCF 服务引用,因为它打算被使用。然后创建一个类,该类为您要调用的每个服务方法提供一个方法,并公开您需要在 PowerShell 中使用的参数。
class MyProxy
{
public string Url { get; set; }
public string SomeParameterForTheHeader { get; set; }
public string CallSomeMethod(string input1, string input2)
{
// create WCF context using this.Url
// create MessageHeader using this.SomeParameterForTheHeader and add it to the context
// call SomeMethod on the context using input1 and input2
}
}
编译它并在 PowerShell 脚本中使用程序集和类。
[System.Reflection.Assembly]::LoadWithPartialName("MyAssembly") > $null
$ref = New-Object MyNamespace.MyProxy()
$ref.Url = "http://..."
$ref.SomeParameterForTheHeader = "your value here"
$ref.CallSomeMethod("input1", "input2")