为具有多个 wsdl 版本的第三方集成创建 C# 库的策略

Strategy for creating C# library for Third party integration with multiple wsdl versions

我们需要将第三方 SOAP api 与我们的系统集成。由于我们是 SaaS 解决方案提供商,我们需要支持所有版本的第三方。 我们的配置是客户 A 的版本为 1.8,客户 B 的版本为 2.0。 (新版本可能需要几个月的时间。)

我正在寻找的是创建适用于所有版本的库的一般策略。

作为一种解决方案,我认为在单个 C# 库中明智地创建多个命名空间版本。

  1. TP1.DLL
    • 命名空间 - TP1_v1.8
      • 实体 1(代理 class)
      • 实体 2(代理 class)
    • 命名空间 - TP2_v2.0
      • 实体 1(代理 class)
      • 实体 2(代理 class)

我想要所有实体的包装器 class,无论版本如何。所以我将调用该包装器 class,它将使用所需版本初始化对象。

我该怎么做?这种情况的处理方式正确吗?

如果需要任何进一步的信息,请告诉我!

谢谢!

安库尔·卡拉瓦迪亚

您可以使用以下解决方案来解决您的问题,这对您的实施有帮助。

--> 首先创建通用接口,它对所有相同类型的通用标识符很有用

--> 按版本名创建单独的命名空间

 DefaultNameSpace : ABC.XYZ
 Version          : 1.6.2

Then make the namespace patterns as

e.g. ABC.XYZ.V162  (Replcing . and set prefix as per classname norms (always start with Alphabet ) )

Create Class under above namespace with implementing interface

--> 为所有版本创建相同的类名(例如 class1、class2 在版本 v1、v2 中通用,具有不同的实现)

--> 创建下面的通用函数来生成相关对象

    public static iTestInterface GetEntity(string className)
    {
        string versionPrefix = "v_";
        string strVersion =  1.6.2; 

        string dllPath =System.Web.HttpRuntime.BinDirectory; 
        string dllName = "dllName.dll";
        string Version = versionPrefix +  

        string strclassNameWithFullPath = dllPath + Version.Replace(".", "") + "." + className; 
        try
        {
            string strAssemblyWithPath = string.Concat(dllPath, dllName);

            if (!System.IO.File.Exists(strAssemblyWithPath))
            {
                return null;
            }

            System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFile(strAssemblyWithPath);
            Type t = assembly.GetType(strclassNameWithFullPath);

            object obj = Activator.CreateInstance(t);
            return (iTestInterface)obj;
        }
        catch (Exception exc)
        {
            //string errStr = string.Format("Error occured while late assembly binding. dllPath = {0}, dllName = {1}, className = {2}.", dllPath, dllName, className);
            return null;
        }
    }

--> 调用函数如下

 iTestInterface obj = GetEntity(classnameString);

--> 调用相关对象方法。以上调用对于所有相关 类.

都是通用的

感谢和问候 谢莉什·乔普拉