SOAP request

  • I'm trying to test a SOAP request from powershell, but getting an error. I goggled error but solutions don't seem to be working... any suggestions to fix?

    Error:

    Reading and converting file to XmlDocument: c:\miscjunk\soap-W.txt

    Sending SOAP Request To Server: http://www.webservicex.net/globalweather.asmx?WSDL

    Initiating Send.

    Send Complete, Waiting For Response.

    Exception calling "GetResponse" with "0" argument(s): "The underlying connection was closed: The connection was closed unexpectedly."

     

     

    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 c:\miscjunk\soap-W.txt -URL "http://www.webservicex.net/globalweather.asmx?WSDL"
  • Thanks for posting your issue and hopefully someone will answer soon.

    This is an automated bump to increase visibility of your question.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply