1

I used the PowerShell New-WebServiceProxy commandlet to get a connection with a WebService(WCF/SOAP). It´s possible to connect to the WebService but when I want to execute a methode I´m getting a access denied. The access denied is because the WebService needs a custom message header. But this is not possible with New-WebServiceProxy.

Question: What is the easiest way to connect/use the WebService and add the message header? Is there a PowerShell example script? (My prefered language is PowerShell in that case)

BTW: Yes I know that there is a Question very similar to my: Add custom SOAP header in PowerShell using New-WebServiceProxy

Thank you in advance!

Community
  • 1
  • 1
LaPhi
  • 5,675
  • 21
  • 56
  • 78

1 Answers1

2

This is more of a workaround, but maybe it works for you. Instead of using the cmdlet, create a C# oder VB.NET Project, add the WCF service reference as it is intended to be used. Then create a class that has a method for every service method you want to call and exposes the arguments you need to use in 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
    }
}

Compile it and use the assembly and class in your PowerShell script.

[System.Reflection.Assembly]::LoadWithPartialName("MyAssembly") > $null
$ref = New-Object MyNamespace.MyProxy()
$ref.Url = "http://..."
$ref.SomeParameterForTheHeader = "your value here"
$ref.CallSomeMethod("input1", "input2")
Turrau
  • 452
  • 1
  • 4
  • 11