Soap requests are ubiquitous in Web services, such as the WCF service and the traditional ASMX asp.net Web service. If it is too complicated to test whether the SOAP service is easy to implement through Web programming, the following script fragment (snippet) will easily complete the PowerShell test and invoke the SOAP service:
This is a piece of program code.
Copy Code code as follows:
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.facilities.co.za/valid8service/valid8service/Valid8Address '")
$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
}
$url = ' Http://www.facilities.co.za/valid8service/valid8service.asmx '
$soap = [xml]@ '
<?xml version= "1.0" encoding= "Utf-8"?>
<soap12:envelope xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd= "http://www.w3.org/2001/ XmlSchema "xmlns:soap12=" Http://www.w3.org/2003/05/soap-envelope ">
<soap12:Body>
<valid8address xmlns= "Http://www.facilities.co.za/valid8service/valid8service" >
<ID>string</ID>
<Address1></Address1>
<Address2></Address2>
<Address3></Address3>
<Address4></Address4>
<Address5></Address5>
<Address6></Address6>
<PostCode></PostCode>
</Valid8Address>
</soap12:Body>
</soap12:Envelope>
'@
$ret = Execute-soaprequest $soap $url
The System.Xml.XmlDocument object is stored in the $ret variable here, and if you need to see what's in it, you can output it to a local file by Export-clixml this cmdlet.
This is a piece of program code.
Copy Code code as follows:
$ret | Export-clixml C:\1.xml; Get-content C:\1.xml