【问题标题】:Strategy for creating C# library for Third party integration with multiple wsdl versions为与多个 wsdl 版本的第三方集成创建 C# 库的策略
【发布时间】:2016-01-18 18:46:54
【问题描述】:

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

我正在寻找的是创建可与所有版本一起使用的库的一般策略。

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

  1. TP1.DLL
    • 命名空间 - TP1_v1.8
      • Entity1(代理类)
      • Entity2(代理类)
    • 命名空间 - TP2_v2.0
      • Entity1(代理类)
      • Entity2(代理类)

我想要所有实体的包装类,无论版本如何。所以我会调用那个包装类,它会用所需的版本初始化对象。

我该怎么做?处理这种情况是否正确?

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

谢谢!

安库尔卡拉瓦迪亚

【问题讨论】:

    标签: c# api soap wsdl multiple-versions


    【解决方案1】:

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

    --> 首先创建通用接口,该接口可用于所有相同类型的通用标识符

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

     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);
    

    --> 调用相关的对象方法。以上调用对于所有相关类都是通用的。

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

    【讨论】:

      猜你喜欢
      • 2019-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-29
      • 1970-01-01
      • 1970-01-01
      • 2019-02-06
      相关资源
      最近更新 更多