cannot unregister the given destination configuration


最近需要对接SAP接口,发现几个小问题总结下

1、RFC调用使用WEB程序部署时容易出现错误

 IDestinationConfiguration ID = new RFC_SetUp();

 RfcDestinationManager.RegisterDestinationConfiguration(ID);

RfcDestination destination = RfcDestinationManager.GetDestination("SAPMS");
RfcRepository repository = destination.Repository;
IRfcFunction rfcFunction = repository.CreateFunction("BAPI_USER_GET_DETAIL");

IIS 部署完成,第一次初始化的时候需要配置ID需要执行 “” RfcDestinationManager.RegisterDestinationConfiguration(ID);“”

第二次访问是就不需要配置注册ID,所以就需要加个判断。

以上问题再CS端直接调用不会产生,只有IIS端部署会出现这种问题。

  /// 
    /// RFC的连接配置
    /// 
    public class RFC_SetUp : IDestinationConfiguration
    {
        RFC_Parameters_Model rfc_Parameters = new RFC_Parameters_Model();
        public RfcConfigParameters GetParameters(string destinationName)
        {
            if (destinationName.Equals("SAPMS"))
            {
                RfcConfigParameters rfcParams = new RfcConfigParameters();
                rfc_Parameters = Configuration_RFC();//获取连接参数
                rfcParams.Add(RfcConfigParameters.AppServerHost, ConfigurationManager.AppSettings["RFC_AppServerHost"]);
                rfcParams.Add(RfcConfigParameters.SystemNumber, ConfigurationManager.AppSettings["RFC_SystemNumber"]);
                rfcParams.Add(RfcConfigParameters.User, ConfigurationManager.AppSettings["RFC_User"]);
                rfcParams.Add(RfcConfigParameters.Password, ConfigurationManager.AppSettings["RFC_Password"]);
                rfcParams.Add(RfcConfigParameters.Client, ConfigurationManager.AppSettings["RFC_Client"]);
                rfcParams.Add(RfcConfigParameters.Language, ConfigurationManager.AppSettings["RFC_Language"]);
                rfcParams.Add(RfcConfigParameters.PoolSize, ConfigurationManager.AppSettings["RFC_PoolSize"]);
                rfcParams.Add(RfcConfigParameters.MaxPoolSize, ConfigurationManager.AppSettings["RFC_MaxPoolSize"]);
                rfcParams.Add(RfcConfigParameters.IdleTimeout, ConfigurationManager.AppSettings["RFC_IdleTimeout"]);
                return rfcParams;
            }
            else
            {
                return null;
            }
        }
        public bool ChangeEventsSupported()
        {
            return false;
        }
        public event RfcDestinationManager.ConfigurationChangeHandler ConfigurationChanged;

        private RFC_Parameters_Model Configuration_RFC()
        {
            rfc_Parameters.RFC_AppServerHost = ConfigurationManager.AppSettings["RFC_AppServerHost"];
            rfc_Parameters.RFC_SystemNumber = ConfigurationManager.AppSettings["RFC_SystemNumber"];
            rfc_Parameters.RFC_User = ConfigurationManager.AppSettings["RFC_User"];
            rfc_Parameters.RFC_Password = ConfigurationManager.AppSettings["RFC_Password"];
            rfc_Parameters.RFC_Client = ConfigurationManager.AppSettings["RFC_Client"];
            rfc_Parameters.RFC_Language = ConfigurationManager.AppSettings["RFC_Language"];
            rfc_Parameters.RFC_PoolSize = ConfigurationManager.AppSettings["RFC_PoolSize"];
            rfc_Parameters.RFC_MaxPoolSize = ConfigurationManager.AppSettings["RFC_MaxPoolSize"];
            rfc_Parameters.RFC_IdleTimeout = ConfigurationManager.AppSettings["RFC_IdleTimeout"];
            return rfc_Parameters;
        }
    }
 /// 
    /// 连接SAP
    /// 
    public class RFC_Connection
    {
        IDestinationConfiguration ID;
        public RfcDestination dest;
        public RfcRepository repository;
        /// 
        /// 测试连接SAP
        /// 
        /// 
        public string ConnSap()
        {
           String message = "";
            bool result = false;
            try
            {
                IDestinationConfiguration ID = new RFC_SetUp();
                if (RfcDestinationManager.TryGetDestination("SAPMS") == null)
                {
                    RfcDestinationManager.RegisterDestinationConfiguration(ID);
                }
                RfcDestination destination = RfcDestinationManager.GetDestination("SAPMS");
                RfcRepository repository = destination.Repository;
                IRfcFunction rfcFunction = repository.CreateFunction("BAPI_USER_GET_DETAIL");

                rfcFunction.SetValue("USERNAME", "USER");
                rfcFunction.Invoke(destination);

                message += rfcFunction.GetValue("LOGONDATA").ToString() + "\r\n";
                message += rfcFunction.GetValue("DEFAULTS").ToString() + "\r\n";
                message += rfcFunction.GetValue("ADDRESS").ToString() + "\r\n";
                message += rfcFunction.GetValue("COMPANY").ToString() + "\r\n";
                message += rfcFunction.GetValue("SNC").ToString() + "\r\n";
                message += rfcFunction.GetValue("REF_USER").ToString() + "\r\n";
                message += rfcFunction.GetValue("ALIAS").ToString() + "\r\n";
                message += rfcFunction.GetValue("UCLASS").ToString() + "\r\n";
                message += rfcFunction.GetValue("LASTMODIFIED").ToString() + "\r\n";
                message += rfcFunction.GetValue("ISLOCKED").ToString() + "\r\n";
                message += rfcFunction.GetValue("IDENTITY").ToString() + "\r\n";
                message += rfcFunction.GetValue("ADMINDATA").ToString() + "\r\n";
                message += rfcFunction.GetValue("DESCRIPTION").ToString() + "\r\n";
          
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            finally
            {
                if (ID != null)
                {
                    RfcDestinationManager.RegisterDestinationConfiguration(ID);
                    RfcDestinationManager.UnregisterDestinationConfiguration(ID);
                }
            }
            return message;
        }
    }

  2、IIS部署需要兼容32位