I have a script that is using PowerShell 5.1 and calling New-WebServiceProxy. I want to make this work in PowerShell Core (7.1).
I have spent several hours trying to resolve this issue. Some of the best places I have found are "https://www.powershellbros.com/send-soap-message-powershell/". The article at "https://www.itprotoday.com/powershell/getting-started-soap-based-web-services-and-powershell" might have been perfect, but the page does not show the PowerShell.
Then I found an un-answered question at "https://stackoverflow.com/questions/69059545/using-powershells-invoke-webrequest-with-a-soap-request" that lead me down the Invoke-WebRequest commandlet path in my example.
I could include the WSDL if it helps, but I don't think it matters.
I ran Fiddler and used the PowerShell 5.1 version script. I captured the following packets. (Abbreviated)
GET http://XXX/CardiocomIVRService.asmx?wsdl HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 4.0.30319.42000)
Host: dev-dc1-net01.vadev.cardiocom.net
Connection: Keep-Alive
<<wsdl excluded="" for="" brevity="">>
Then
POST http://XXX/CardiocomIVRService.asmx HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 4.0.30319.42000)
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://cardiocom.com/SaveIVRSessionResponseString"
Host: dev-dc1-net01.vadev.cardiocom.net
Content-Length: 2832
Expect: 100-continue
<soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:body>
<saveivrsessionresponsestring xmlns="http://cardiocom.com/">
<response>
<CardiocomIVRSession QuestionSetType="healthcheck" DeviceType="8192">
This works in 5.1.
Now on to 7.1
Here is my current script code.
#REQUIRES -version 7.0
[String] $URL = 'http://XXX/CardiocomIVRService.asmx'
$SOAPRequest = @"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soapenv="http:
<soap:Body>
<SaveIVRSessionResponseString xmlns="http://cardiocom.com/">
<response>
<CardiocomIVRSession QuestionSetType="healthcheck" DeviceType="8192">
</response>
</SaveIVRSessionResponseString>
</soap:Body>
</soap:Envelope>
"@
$Headers = @{
'SOAPAction' = 'http://cardiocom.com/SaveIVRSessionResponseString'
'Host' = 'dev-dc1-net01.vadev.cardiocom.net'
'Expect' = '100-continue'
'Content-Length' = $SOAPRequest.Length
'Transfer-Encoding' = 'chunked'
'Content-Type' = 'text/xml; charset=utf-8'
'User-Agent' = 'Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 4.0.30319.42000)'
}
Write-Host $( $headers | Out-String)
Write-Host "Len=$($SOAPRequestByte.Length)"
$response = Invoke-WebRequest -Uri $URL `
-Headers $Headers `
-Body $SOAPRequest `
-Method 'POST' `
-SkipHttpErrorCheck `
-SkipHeaderValidation `
-SkipCertificateCheck `
-UseDefaultCredentials `
-AllowUnencryptedAuthentication
Write-Host "Status: $($response.StatusCode)"
Write-Host "Raw: $($response.RawContent)"
This returns the following.
Name Value
---- -----
Content-Length 454
SOAPAction http://cardiocom.com/SaveIVRSessionResponseString
Host dev-dc1-net01.vadev.cardiocom.net
Expect 100-continue
Content-Type text/xml; charset=utf-8
Transfer-Encoding chunked
User-Agent Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 4.0.30319.42000)
Len=0
Status: 400
Raw: HTTP/1.1 400 BadRequest
Cache-Control: private
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Thu, 03 Feb 2022 14:30:04 GMT
Content-Type: text/xml; charset=utf-8
Content-Length: 0
I see nothing in Fiddler. I think I am close, but missing some detail.
What I have tried:
I have tried many versions to get to this point. Finding information on using PowerShell Core vs 5.1 makes searching challenging.