CacheSetting.AlwaysOn only works for ctor taking Binding and EndpointAddress with same instances
- Dominant language
- C#
- Stars
- 1.8k
- Forks
- 576
- Avg merge
- 6d 9h
- Merged PRs (30d)
- 2
Description
**Describe the bug**
I seems like caching does not work if you follow the examples on the following page:
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/channel-factory-and-caching
The page states that:
```
class Program
{
static void Main(string[] args)
{
ClientBase.CacheSettings = CacheSettings.AlwaysOn;
foreach (string msg in messages)
{
using (TestClient proxy = new TestClient (new BasicHttpBinding(), new EndpointAddress(address)))
{
// ...
proxy.Test(msg);
// ...
}
}
}
}
// Generated by SvcUtil.exe
public partial class TestClient : System.ServiceModel.ClientBase, ITest { }
```
"In the above code, all instances of TestClient will use the same channel factory."
But for caching to work, only the above ctor works if the same instance of BasicHttpBinding is passed(in the example above a new instance is used for BasicHttpBinding, which causes a new channel factory to be created and added to the cache(the cache grows for each new client). All other ctors on the generated client does also not work as these overloads creates new binding instances.
Is this expected behavior?
Contributor guide
Assessment
This issue has not been assessed yet.