title: Process SOAP request from powershell
body: <p>I try to utilise the code example. But I am unsuscessful. Can any one pick up an error? (I know about New-WebServiceProxy cmdlet.)</p>
  
  <pre><code>function Execute-SOAPRequest 
  ( 
       [Xml]    $SOAPRequest, 
          [String] $URL 
  ) 
  { 
          write-host “Sending SOAP Request To Server: $URL” 
          $soapWebRequest = [System.Net.WebRequest]::Create($URL) 
          $soapWebRequest.Headers.Add("SOAPAction" ,"http://www.webservicex.net/globalweather.asmx?WSDL/GetWeather") 
  
      $soapWebRequest.ContentType = 'text/xml;charset="utf-8"' 
      $soapWebRequest.Accept      = “text/xml” 
      $soapWebRequest.Method      = “POST” 
  
      write-host “Initiating Send.” 
      $requestStream = $soapWebRequest.GetRequestStream() 
      $SOAPRequest.Save($requestStream) 
      $requestStream.Close() 
  
      write-host “Send Complete, Waiting For Response.” 
      $resp = $soapWebRequest.GetResponse() 
      $responseStream = $resp.GetResponseStream() 
      $soapReader = [System.IO.StreamReader]($responseStream) 
      $ReturnXml = [Xml] $soapReader.ReadToEnd() 
      $responseStream.Close() 
  
      write-host “Response Received.” 
  
        return $ReturnXml 
  }
  
  function Execute-SOAPRequestFromFile 
  ( 
          [String] $SOAPRequestFile, 
          [String] $URL 
  ) 
  { 
          write-host “Reading and converting file to XmlDocument: $SOAPRequestFile” 
          $SOAPRequest = [Xml](Get-Content $SOAPRequestFile)
  
  
      return $(Execute-SOAPRequest $SOAPRequest $URL) 
  }
  
  $x = Execute-SOAPRequestFromFile  -SOAPRequestFile soap-W.txt -URL "http://www.webservicex.net/globalweather.asmx?WSDL"
  </code></pre>
  
  <p>The file soap-W.txt:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.webserviceX.NET" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"&gt;
  &lt;SOAP-ENV:Body&gt;
  &lt;tns:GetWeather xmlns:tns="http://www.webserviceX.NET"&gt;
  &lt;tns:CityName&gt;Tampa&lt;/tns:CityName&gt;
  &lt;tns:CountryName&gt;United States&lt;/tns:CountryName&gt;
  &lt;/tns:GetWeather&gt;
  &lt;/SOAP-ENV:Body&gt;
  &lt;/SOAP-ENV:Envelope&gt;
  </code></pre>
  
  <p>Server return error 500. Query via New-WebServiceProxy is successfull.</p>