# SOAP Request Multi Threading - Jobs are not started

**URL:** <https://forums.powershell.org/t/soap-request-multi-threading-jobs-are-not-started/23773>\
**Category:** PowerShell Help\
**Created:** [March 13, 2024, 3:44pm UTC](https://forums.powershell.org/t/soap-request-multi-threading-jobs-are-not-started/23773 "2024-03-13T15:44:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrej](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@Andrej](https://forums.powershell.org/u/Andrej)\
**Post date:** [March 13, 2024, 3:44pm UTC](https://forums.powershell.org/t/soap-request-multi-threading-jobs-are-not-started/23773/1 "2024-03-13T15:44:51Z")

</div>

Hello,  
The following code works as intended - i.e. every 5s a SOAP request is transmitted to the SOAP Server.

```auto
 # 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.

```auto
# 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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [April 12, 2024, 3:45pm UTC](https://forums.powershell.org/t/soap-request-multi-threading-jobs-are-not-started/23773/2 "2024-04-12T15:45:11Z")

</div>

Closed on April 12, 2024, 3:45pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
