SOAP request through power shell

$postBody = Get-Content -Raw -Path "E:\body.xml"
$url = "https://someservice/service"
$currentDate = Get-Date
$guid = [guid]::NewGuid()
$nameOfCertificate = "<certname>"
$headers = @{"SOAPAction" = "<MethodName>"}


$currentDate</b:MessageText>"

#Get current location
$currentLocation = (Get-Location).Path

Write-Host "ServerName:$env:COMPUTERNAME"

#Set Location where to get the cerificate
Set-Location Cert:\LocalMachine\My

#Get the certificate to be used
$certificate = Get-ChildItem | where {$_.Subject.Contains($nameOfCertificate)}

try{
    $postBody = $postBody.Replace("9bfcb841-2701-4ba4-ada7-0d44445b2dbe",$guid)
 
     
    $response = Invoke-WebRequest -Method Post -Uri "$url" -Body $postBody -ContentType 'text/xml' -Headers $headers -Certificate $certificate

    $xmlResponse = [xml]$response.Content
 

 
}
catch [exception]

{
   echo $_.Exception|format-list -force
   #echo $_.Exception.Message
}
finally{
    #Return to drive and out of the certificate path
    Set-Location $currentLocation
}


Please add your comments if it helps....

Comments

Popular posts from this blog

Base 64 encoding and decoding

LINQ Queries with GROUP BY, INNER JOIN, COUNT and SUM: Examples

How to write Custom delete Confirmation Modal for Kendo Grid in MVC: