Posting SOAP request from Windows Powershell

A previous post on this blog showed how posting a SOAP request from the command line on Linux could be done.

Following the post about Invoke-Web-Request, I’ll show how to achieve the same task using Windows Powershell v3 CTP 1.

The first step is to build a sample SOAP request and save it on a text file, maybe called “soap.txt”. For the sake of this example I saved it on a temporary folder “C:\Temp”

Afterwards, open a powershell command prompt window and type this in:

Invoke-WebRequest http://[your web service endpoint address] -Method Post -ContentType "text/xml" -InFile C:\Temp\soap.txt -OutFile c:\Temp\soapRes.txt

The command has the following parameters:

  • method: indicating the request should be sent using HTTP POST
  • content type: stating the request is an XML message
  • input file: the SOAP request text file
  • output file: the name and path for saving the SOAP response

After execution, the resulting SOAP response is saved on the temporary folder under the name “soapresult.txt”.



4 thoughts on “Posting SOAP request from Windows Powershell

  1. I tried your solutions,, works great,, but Im trying to get the result to display on the console. if I omit the -OutFile parameter I get: Invoke-WebRequest : ‘”utf-8″‘ is not a supported encoding name..
    Cannot figure out how to do it.

  2. Doing more test discovered that my WSDL is presented by a Glassfish V2, and it sets the encoding to “utf-8” (enclosed by double quotes),, that is causing problems with the IWR and I dont know how to fix it.

  3. Just what I’m looking for. Unfortunately, it fails a SOAP post but successul with LInux. I get a error: The remote server returned an error: (404) Not Found. I would love to be able to use this new commandlet in v3.

    • Hi Chris,

      the HTTP 404 code usually means you have a mispelled URL. I suggest checking your parameter for a typo. You might want to follow my new address:

      Kind regards,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s