• RfcDestinationManager.UnregisterDestinationConfiguration时报错cannot unregister the given destination configuration


    在使用NCO访问SAP的RFC时,我的程序代码是这么写的:

            string destinationName = "EWM_700_GROUP";
            IDestinationConfiguration ID;
            RfcDestination prd;
    
            public EWM01()
            {
                try
                {
                    ID = new MyBackendConfig();
        RfcDestinationManager.RegisterDestinationConfiguration(ID);
                    prd = RfcDestinationManager.GetDestination(destinationName);//获得目的对象
                }
                catch (Exception ex)
                {
                    LogService.WatchLog("初始化EWM01异常:" + ex.Message.ToString() + Environment.NewLine);
                    throw ex;
                    //Configuration.OnlyOne().messageService.Error(ex, "EWM01");
                }
            }
    
            public void Dispose()
            {
    RfcDestinationManager.UnregisterDestinationConfiguration(ID);
    
            }    

    这段代码是写在一个WebService里,从表面上看,似乎没什么问题

    然而,实际上,程序大多数时候都好使,但是每天都会有几次出现这种问题,如下图:

    这句话的意思是,无法注销所给的目的配置,很容易就定位到,问题出在这一句

    RfcDestinationManager.UnregisterDestinationConfiguration(ID);

    但是,这一句不是用来断开连接的么??然后,我就开始查资料

    关于这个问题的资料基本都是国外的,国内貌似还没人回答这个问题,好在我英文也不是很差,最后,让我找到了几个有用的信息

    原文地址是:https://stackoverflow.com/questions/22242451/how-to-check-whether-the-sap-system-is-connected-to-net-or-not

    这个国外哥们儿告诉我,NCO使用的是连接池机制,所以我们不必自己手动去创建连接和断开连接,NCO的运行库会帮我们做

    在创建一个RFC的function实例的时候,就会触发连接,总之,我们不用去管打开或者关闭连接的事,我们只需要处理那些可能在连接过程中发生的异常就好了

    还有一个哥们儿,也发表了类似的观点,不过他主要是跟我们讲注册那一步的意义

    原文出处:https://archive.sap.com/discussions/message/14955463#14955463

    有了这两个哥们的回答,我就大概可以确定了,所谓的RfcDestinationManager.RegisterDestinationConfiguration(ID);注册

    只不过是告诉RfcDestinationManager管理器,SAP那边的地址配置信息而已,真正的建立连接和断开连接跟它没有关系

    既然如此,那么这个问题的解决方案就很简单了,直接去掉RfcDestinationManager.UnregisterDestinationConfiguration(ID);这句就好了

    另外,为了以防万一,最好在每次注册之前,做一个判断,以免重复注册引起报错

    所以,最后,经过调整后代码就是

            public EWM01()
            {
                try
                {
                    ID = new MyBackendConfig();
                    //如果RFC管理器中不存在指定的目的地
                    if (RfcDestinationManager.TryGetDestination(destinationName) == null)
                    {
                        //则向RFC管理器注册目的地配置
                        RfcDestinationManager.RegisterDestinationConfiguration(ID);
                    }
                    prd = RfcDestinationManager.GetDestination(destinationName);//获得目的对象
                }
                catch (Exception ex)
                {
                    LogService.WatchLog("初始化EWM01异常:" + ex.Message.ToString() + Environment.NewLine);
                    throw ex;
                    //Configuration.OnlyOne().messageService.Error(ex, "EWM01");
                }
            }
    
            public void Dispose()
            {
                ////如果RFC管理器中存在指定的目的地
                //if (RfcDestinationManager.TryGetDestination(destinationName) != null)
                //{
                //    //则注销RFC管理器的目的地配置
                //    RfcDestinationManager.UnregisterDestinationConfiguration(ID);
                //}
            }

    希望能对遇到同样问题的人有帮助

    本文为作者原创,如需转载,请标明出处

  • 相关阅读:
    CSS 基础语法
    标签
    HDU 5487 Difference of Languages BFS
    HDU 5473 There was a kingdom 凸包 DP
    HDU 5468 Puzzled Elena 莫比乌斯反演
    BNU 3692 I18n 模拟
    补题列表
    POJ 3241 曼哈顿距离最小生成树 Object Clustering
    UVa 1309 DLX Sudoku
    CodeForces Round #320 Div2
  • 原文地址:https://www.cnblogs.com/mooncher/p/7359045.html
Copyright © 2020-2023  润新知