溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

通過(guò)PowerShell執(zhí)行SOAP請(qǐng)求

發(fā)布時(shí)間:2020-06-27 13:53:16 來(lái)源:網(wǎng)絡(luò) 閱讀:437 作者:fuhj02 欄目:編程語(yǔ)言

     SOAP的請(qǐng)求在Web Service是無(wú)處不在的,像WCF服務(wù)和傳統(tǒng)ASMX asp.net的web Service。如果要測(cè)試SOAP服務(wù)是否好用通過(guò)web編程來(lái)實(shí)現(xiàn)就顯得太過(guò)于復(fù)雜了,下面的腳本片段(snippet)將會(huì)輕而易舉的完成通過(guò)powershell測(cè)試和調(diào)用SOAP服務(wù):

 
  1. function Execute-SOAPRequest
  2. (
  3. [Xml] $SOAPRequest,
  4. [String] $URL
  5. )
  6. {
  7. write-host "Sending SOAP Request To Server: $URL"
  8. $soapWebRequest = [System.Net.WebRequest]::Create($URL)
  9. $soapWebRequest.Headers.Add("SOAPAction","`"http://www.facilities.co.za/valid8service/valid8service/Valid8Address`"")
  10.  
  11. $soapWebRequest.ContentType = "text/xml;charset=`"utf-8`""
  12. $soapWebRequest.Accept = "text/xml"
  13. $soapWebRequest.Method = "POST"
  14.  
  15. write-host "Initiating Send."
  16. $requestStream = $soapWebRequest.GetRequestStream()
  17. $SOAPRequest.Save($requestStream)
  18. $requestStream.Close()
  19.  
  20. write-host "Send Complete, Waiting For Response."
  21. $resp = $soapWebRequest.GetResponse()
  22. $responseStream = $resp.GetResponseStream()
  23. $soapReader = [System.IO.StreamReader]($responseStream)
  24. $ReturnXml = [Xml] $soapReader.ReadToEnd()
  25. $responseStream.Close()
  26.  
  27. write-host "Response Received."
  28.  
  29. return $ReturnXml
  30. }
  31.  
  32. $url = 'http://www.facilities.co.za/valid8service/valid8service.asmx'
  33. $soap = [xml]@'
  34. <?xml version="1.0" encoding="utf-8"?>
  35. <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">
  36. <soap12:Body>
  37. <Valid8Address xmlns="http://www.facilities.co.za/valid8service/valid8service">
  38. <ID>string</ID>
  39. <Address1></Address1>
  40. <Address2></Address2>
  41. <Address3></Address3>
  42. <Address4></Address4>
  43. <Address5></Address5>
  44. <Address6></Address6>
  45. <PostCode></PostCode>
  46. </Valid8Address>
  47. </soap12:Body>
  48. </soap12:Envelope>
  49. '@
  50. $ret = Execute-SOAPRequest $soap $url

      在這里得到的$ret變量中存儲(chǔ)的是System.Xml.XmlDocument對(duì)象,如果需要查看其中的具體內(nèi)容可以通過(guò)Export-Clixml這個(gè)cmdlet將其輸出到本地文件中查看。

$ret | Export-Clixml c:\1.xml;Get-Content c:\1.xml

作者: 付海軍
出處:http://fuhj02.blog.51cto.com
版權(quán):本文版權(quán)歸作者和51cto共有
轉(zhuǎn)載:歡迎轉(zhuǎn)載,為了保存作者的創(chuàng)作熱情,請(qǐng)按要求【轉(zhuǎn)載】,謝謝
要求:未經(jīng)作者同意,必須保留此段聲明;必須在文章中給出原文連接;否則必究法律責(zé)任
個(gè)人網(wǎng)站: http://txj.shell.tor.hu/

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI