首页 > 解决方案 > ClientBase 的替代方案.NET Standard 2.0 的 System.ComponentModel.Primitives 中的 .CacheSetting?

问题描述

一两年前,我们的 WCF 客户端遇到了一些问题。即使在使用新的端点 url 创建了一个全新的客户端之后,客户端仍在使用相同的端点 url,这在最后略有不同。

解决方案是像这样禁用缓存:

public static void TurnOffServiceClientCache<TServiceInterface>() where TServiceInterface : class
{
    try
    {
        if (ClientBase<TServiceInterface>.CacheSetting != CacheSetting.AlwaysOff)
        {
            ClientBase<TServiceInterface>.CacheSetting = CacheSetting.AlwaysOff;
        }
    }
    catch (Exception ex)
    {
        m_log.WriteError($"Error when setting {typeof(TServiceInterface).FullName}-ServiceClient-Caches to AlwaysOff", ex);
        throw;
    }
}

我们目前正在将越来越多的项目从旧框架版本 4.5.2 迁移到 netstandard2.0。

似乎CacheSetting-property 在 netstandard2.0 实现中不可用。还有什么我可以用的吗?

标签: c#wcf.net-standard-2.0

解决方案


推荐阅读