A powershell module to help work with WCF Services.
- New-SecurityToken
- New-WcfChannel
- New-WcfProxyType
- New-WcfServiceEndpoint
- New-WcfWsdlImporter
- Set-WcfBindingConfiguration
Basic understanding of terms such as binding and service endpoint is required.
The module is built against WCF endpoints known as ISHWS provided by SDL's Knowledge Center Content Manager API. The API is power by WCF and the authentication is federated against a security token service implementing WSTrust13 endpoints. One security token service example is active directory federation services.
Pester tests are included both for the ISHWS api but also for WSTrust 13 endpoints. Both are very specific to an environment thus the tests depend on parameters and cannot be automated.
The test scripts acts as a good showcase on how to use the module's cmdlets.
- [Test-ISHExternal.ps1](Pester\Test-ISHExternal.ps1]
- [Test-WSTrust.ps1](Pester\Test-WSTrust.ps1]
Since I don't have access to various soap endpoints, some flows are not implemented and will throw a new NotImplementedException
.
In principal use the commandlets in the following order
- Acquire an importer using
New-WcfWsdlImporter
. This queries the endpoint for metadata. Use the-HttpGet
parameter when you would use the otherwise known?wsdl
query string - Acquire a service endpoint using
New-WcfServiceEndpoint
. The return service endpoint instance acts as a container for the binding and address. - Build the internal proxy types using
New-WcfProxyType
.
At this point you can build the channel for any WCF endpoint. Depending on the service configuration authentication, the channel might require authentication context. Depending on the type do one of the following:
- When username/password then execute
New-WcfChannel
with-Credential
parameter - When windows then execute
New-WcfChannel
. The process's user crendetials will be used. - When federated with security token service then
- Execute
New-SecurityToken
to acquire a symmetric token. As with theNew-WcfChannel
authentication choices same rules apply forNew-SecurityToken
. - Execute
New-WcfChannel
with-Token
parameter.
- Execute
A generic example
$wsImporter=New-WcfWsdlImporter -Endpoint $svcEndpoint -HttpGet
$proxyType=$wsImporter | New-WcfProxyType
$endpoint=$wsImporter | New-WcfServiceEndpoint -Endpoint $svcEndpoint
$channel=New-WcfChannel -Endpoint $endpoint -ProxyType $proxyType
An ISHWS specific example
#Authenticate on the STS and acquire a token
$issuerImporter=New-WcfWsdlImporter -Endpoint $mexUri
$issuerEndpoint=$issuerImporter | New-WcfServiceEndpoint -Endpoint $authentiCationEndpoint
$token=New-SecurityToken -Endpoint $issuerEndpoint -Credential $Credential -AppliesTo $ishWSAppliesTo -Symmetric
#Use the token to build a channel for the /Wcf/API25/Application.svc endpoint
$ishWSimporter=New-WcfWsdlImporter -Endpoint $svcEndpoint -HttpGet
$ishWSproxyType=$ishWSimporter | New-WcfProxyType
$ishEndpoint=$ishWSimporter | New-WcfServiceEndpoint -Endpoint $svcEndpoint
$channel25=New-WcfChannel -Endpoint $ishEndpoint -ProxyType $proxyType -Token $token
#Consume the GetVersion method
$channel25.GetVersion