Hello,
The following code works as intended - i.e. every 5s a SOAP request is transmitted to the SOAP Server.
# Define the SOAP XML request
[string]$Event = "6";
$SoapRequest = @"
...
"@
# Set the content type header for SOAP request
$SoapHeader = @{
...
}
[String]$TargetIP = "173.18.1.3"
[String]$TargetPRT = "8080"
[String]$url = "http://"+$TargetIP+":"+$TargetPRT+"/"
# Loop to send SOAP request every 5 seconds
while ($true)
{
#SendSOAPRequest
$response = Invoke-WebRequest -Uri $url -Method Post -Body $SoapRequest -ContentType "text/xml;charset=utf-8" -Headers $SoapHeader
Start-Sleep -Seconds 5
}
I would like to create 4 threads, each of which is supposed to make a SOAP request. However, with the following code no SOAP Requests are transmitted.
# Define a script block containing the code you want to run in the thread
$threadScriptBlock =
{
# Loop to send SOAP request every 5 seconds
param($Url,$SoapRequest,$SoapHeader)
# ---------------------------------------
# SOAP request
# ---------------------------------------
while ($true)
{
$response = Invoke-WebRequest -Uri $Url -Method Post -Body $SoapRequest -ContentType "text/xml;charset=utf-8" -Headers $SoapHeader
Start-Sleep -Seconds 5
}
}
# ---------------------------------------
# Spawn Threads
# ---------------------------------------
Start-Job -name "A" -Scriptblock $threadScriptBlock -ArgumentList $Url, $SoapRequest, $SoapHeader
Start-Job -name "B" -Scriptblock $threadScriptBlock -ArgumentList $Url, $SoapRequest, $SoapHeader
Start-Job -name "C" -Scriptblock $threadScriptBlock -ArgumentList $Url, $SoapRequest, $SoapHeader
Start-Job -name "D" -Scriptblock $threadScriptBlock -ArgumentList $Url, $SoapRequest, $SoapHeader
With the above code the 4 threads seem are running, however no SOAP requests are issued. Could someone tell me how I have to fix the code, such that each job issues a SOAP request every 5s. Many thanks in advance and Kind regards.
Andrej