Skip to content

Instantly share code, notes, and snippets.

@flq
Created August 17, 2017 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flq/353119dd5471e3e08d1b6375d2a29f8b to your computer and use it in GitHub Desktop.
Save flq/353119dd5471e3e08d1b6375d2a29f8b to your computer and use it in GitHub Desktop.
Acccess discovery service, download all WSDLs for listed services
function indent([parameter(ValueFromPipeline)]$Content)
{
$StringWriter = New-Object System.IO.StringWriter
$XmlWriter = New-Object System.XMl.XmlTextWriter $StringWriter
$xmlWriter.Formatting = "indented"
$xmlWriter.Indentation = 2
$Content.WriteContentTo($XmlWriter)
$XmlWriter.Flush()
$StringWriter.Flush()
Write-Output $StringWriter.ToString()
}
$cfg = ConvertFrom-Json -InputObject (gc .\config.json -Raw)
$webclient = new-object System.Net.WebClient
$webclient.Credentials = new-object System.Net.NetworkCredential($cfg.user, $cfg.pwd)
[xml]$doc = $webclient.DownloadString($cfg.discovery)
$doc.discovery.contractRef.ref | % {
$u = $_
$name = $_.Substring($_.LastIndexOf("/") + 1)
Write-Host "Get WSDL For $name" -ForegroundColor Cyan
Try {
[xml]$webclient.DownloadString($_) | indent | Out-File -FilePath "$name.wsdl"
}
Catch {
Write-Host "Could not download from $u : $_.Exception.Message" -ForegroundColor Yellow
}
}
@flq
Copy link
Author

flq commented Aug 17, 2017

Parallel to this script there is a config.json file that contains the properties user, pwd and the discovery url.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment