Wcf PowerShell和Webservice-添加标题

Wcf PowerShell和Webservice-添加标题,wcf,web-services,powershell,soap,Wcf,Web Services,Powershell,Soap,我使用PowerShell新的WebServiceProxy命令来获得与WebService(WCF/SOAP)的连接。可以连接到WebService,但当我想要执行一个methode时,访问被拒绝。拒绝访问是因为Web服务需要自定义消息头。但这在新的WebServiceProxy中是不可能的 问题:连接/使用Web服务并添加消息头的最简单方法是什么?是否有PowerShell示例脚本? (在这种情况下,我的首选语言是PowerShell) 顺便说一句:是的,我知道有一个问题与我的非常相似: 提

我使用PowerShell新的WebServiceProxy命令来获得与WebService(WCF/SOAP)的连接。可以连接到WebService,但当我想要执行一个methode时,访问被拒绝。拒绝访问是因为Web服务需要自定义消息头。但这在新的WebServiceProxy中是不可能的

问题:连接/使用Web服务并添加消息头的最简单方法是什么?是否有PowerShell示例脚本? (在这种情况下,我的首选语言是PowerShell)

顺便说一句:是的,我知道有一个问题与我的非常相似:


提前谢谢你

这更像是一种变通方法,但也许对你来说是有效的。不要使用cmdlet,而是创建一个C#order 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")