GetTokenCore attempts to close a faulted channel
- Dominant language
- C#
- Stars
- 1.8k
- Forks
- 576
- Avg merge
- 6d 9h
- Merged PRs (30d)
- 2
Description
**Describe the bug**
I experimented with using `WSTrustChannelSecurityTokenProvider` to issue a token via WS-Trust, much like described in https://github.com/dotnet/wcf/issues/4542. Then I ran into a problem when the STS responded with a SOAP Fault, which contained information that the code needed to act on.
The problem is that `GetTokenCore` uses `try..finally` to always call `channel.Close()` ([source code](https://github.com/dotnet/wcf/blob/3e24c115b563d609163e38005d4c2c8f161eeeb5/src/System.ServiceModel.Federation/src/System/ServiceModel/Federation/WSTrustChannelSecurityTokenProvider.cs#L304-L307)), but if the channel has entered a faulted state it results in `CommunicationObjectFaultedException`, which in turn hides the SOAP Fault exception that had been thrown.
I believe the code in the finally block should examine the state of the channel and instead call `Abort()` in a faulted state.
It was just an experiment and I ended up using `WSTrustChannelFactory` instead for this, but I still want to report it, as it could hide valuable exception information in a normal `WsFederationHttpBinding` use case.
**To Reproduce**
Steps to reproduce the behavior:
1. Attempt to request a security token with similar code as found in https://github.com/dotnet/wcf/issues/4542.
2. Make sure the STS responds with a SOAP Fault.
**Expected behavior**
The SOAP Fault exception should not be hidden by a `CommunicationObjectFaultedException`.
**Additional context**
This was tested with .NET 8 and `System.ServiceModel.Federation` version 8.0.0.
Contributor guide
Assessment
This issue has not been assessed yet.