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....
$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
Post a Comment