How to add WS security element to SOAP request in powershell?

Hi all,

I have a SOAP request, the example is below.

  •        2017-11-28T06:11:16.669Z
    
  •        2017-11-28T06:515:16.669Z
    
  •        xxx
    
  •        PASSWORD
    
  •        password
    
  •        2017-11-28T06:11:12.637Z
    
  •     xxx
    
  •     yyy
    
  •     CSV
    
  •     <!--Optional:-->
    
  •     zzz
    
  •     <!--Optional:-->
    
  •     en_US
    
  •     <!--Optional:-->
    
  •     2
    
  •     <!--Optional:-->
    
  •        <!--Zero or more repetitions:-->
    
  •           <!--You may enter the following 2 items in any order-->
    
  •           display_options
    
  •           default
    

And I figured out how to add all parameters to the body.
$URL = “https://expedialc.skillwsa.com/olsa/services/Olsa?WSDL
$proxy = New-WebServiceProxy -Uri $URL

$type = $proxy.GetType().Namespace
$mySubmitDT = ($type + ‘.SubmitReportRequest’)
$mySubmit = New-Object($mySubmitDT)
$mySubmit.customerId = “xxx”
$mySubmit.report = “yyy”
$mySubmit.scopingUserId = “zzz”
$mySubmit.language = “en_US”
$mySubmit.duration = 1

$reportFormatDT = ($type + ‘.reportFormat’)
$reportFormat = New-Object($reportFormatDT)
$reportFormat.value__ = 2

$MapItemtDT = ($type + ‘.MapItem’)
$MapItemt = New-Object($MapItemtDT)
$MapItemt.key = “display_options”
$MapItemt.value = “default”

$mySubmit.reportFormat = $reportFormat
$mySubmit.reportParameters = $MapItemt

#[xml]$result = $proxy.UD_SubmitReport($mySubmit)

But no idea how to add security header with UserToken and Timestamp.

Thanks,
Tatiana

Note that you can’t paste XML here. You’d need to make it a Gist, and paste the Gist URL, just as with code.

Referencing https://stackoverflow.com/questions/1309767/adding-custom-http-headers-to-web-service-proxy, this isn’t a straightforward thing. Because the proxy class is an abstraction, you’d need to do some heavier .NET coding in order to add custom HTTP headers. The WebServiceProxy command itself is meant to be simplistic, and it doesn’t support custom headers.