Created
October 17, 2018 15:37
-
-
Save Stephanevg/b4cd7b1f3236a1078e6e2e191d95d132 to your computer and use it in GitHub Desktop.
Execute a SOAP call using New-WebService behind a proxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Function New-WebServiceProxyProxy { | |
| [CmdletBinding()] | |
| Param( | |
| $proxyURL, | |
| [Parameter(Mandatory=$true)] | |
| $Uri | |
| ) | |
| $proxyObject = [System.Net.WebProxy]::new($proxyURL) | |
| $TempFile = [System.IO.Path]::GetTempFileName() + "_wsdl.xml" | |
| $WebRequest = Invoke-WebRequest -Uri $Uri -Proxy $proxyURL -UseDefaultCredentials | |
| $Content = [XML]$webRequest.Content | |
| $FirstChild = $Content.FirstChild | |
| if($FirstChild.Name -eq "xml"){ | |
| $null = $Content.RemoveChild($FirstChild) | |
| } | |
| $Content.OuterXml | Out-File -FilePath $TempFile | |
| $Hash = @{} | |
| $Hash.Uri = "file://" + $TempFile | |
| $webProx = New-WebServiceProxy @Hash | |
| $webProx.proxy = $proxyObject | |
| remove-item $TempFile | |
| return $webProx | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment