Skip to content

Instantly share code, notes, and snippets.

@Stephanevg
Created October 17, 2018 15:37
Show Gist options
  • Select an option

  • Save Stephanevg/b4cd7b1f3236a1078e6e2e191d95d132 to your computer and use it in GitHub Desktop.

Select an option

Save Stephanevg/b4cd7b1f3236a1078e6e2e191d95d132 to your computer and use it in GitHub Desktop.
Execute a SOAP call using New-WebService behind a proxy
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