【问题标题】:Connect to RFC destination using several SAP users concurrently同时使用多个 SAP 用户连接到 RFC 目标
【发布时间】:2020-01-13 10:06:24
【问题描述】:

我有一个 .Net 应用程序,用于通过它创建 SAP 销售订单。当我使用(通用)单个 SAP 用户 ID 登录到 rfcDestination 时,它工作得很好。但它不适用于具有不同用户 ID 的并发登录。我看到了 2 个案例:

1) 当我使用用户 id 登录时,例如 test1(SAP 用户),它连接成功。

2)当我使用不同的用户和错误的密码登录时,它仍然可以连接。

我不想注销 test1 会话,因为我想同时登录。我如何做到这一点。以下是我到目前为止尝试过的代码

 SAPConnection objDestConfig = new SAPConnection();
 objDestConfig.AddOrEditDestination(appserver, Name, instanceno, systemid, txt_user.Text, 
txt_password.Text, client, "E");
                    RfcDestination prd = RfcDestinationManager.TryGetDestination(Name);

                    if (prd == null)
                    {
                        RfcDestinationManager.RegisterDestinationConfiguration(objDestConfig);
                        prd = RfcDestinationManager.GetDestination(Name);

                    }
                    //   }


                    //Establishing connection with SAP system
                    // RfcDestination dest = RfcDestinationManager.GetDestination(Name);
                    prd.Ping();   //always returns true even for incorrect password if the destination is registered.

 public SAPConnection()
    {
        //check for available SAP destinations
        availableDestinations = new Dictionary<string, RfcConfigParameters>();
    }

    public RfcConfigParameters GetParameters(string destinationName)
    {
        //reading current SAP destination configurations
        RfcConfigParameters foundDestination;
        availableDestinations.TryGetValue(destinationName, out foundDestination);
        return foundDestination;
    }

    public bool ChangeEventsSupported()
    {
        return true;
    }

    public event RfcDestinationManager.ConfigurationChangeHandler ConfigurationChanged
    {
        add
        {
            changeHandler = value;
        }
        remove
        {                
        }
    }

    //removes the destination that is known under the given name
    public void RemoveDestination(string name)
    {
        if (name != null && availableDestinations.Remove(name))
        {
            changeHandler(name, new RfcConfigurationEventArgs(RfcConfigParameters.EventType.DELETED));
        }
    }

    //allows adding or modifying a SAP destination for a specific application server
    public void AddOrEditDestination(string appserver, string name, string systemnumber, string systemid, string user, string password, string client, string language)
    {            
        RfcConfigParameters parameters = new RfcConfigParameters();
        parameters[RfcConfigParameters.Name] = name;            
        parameters[RfcConfigParameters.User] = user;
        parameters[RfcConfigParameters.Password] = password;
        parameters[RfcConfigParameters.Client] = client;
        parameters[RfcConfigParameters.Language] = language;
        parameters[RfcConfigParameters.AppServerHost] = appserver;
        parameters[RfcConfigParameters.SystemNumber] = systemnumber;
        parameters[RfcConfigParameters.SystemID] = systemid;
        RfcConfigParameters existingConfiguration;            
        if (availableDestinations.TryGetValue(name, out existingConfiguration))
        {
            //modifying SAP destination
            //if a destination of that name existed before, we need to fire a change event
            availableDestinations[name] = parameters;
            RfcConfigurationEventArgs eventArgs = new RfcConfigurationEventArgs(RfcConfigParameters.EventType.CHANGED, parameters);
            changeHandler(name, eventArgs);
        }
        else
        {
            //adding new SAP destination
            availableDestinations[name] = parameters;
        }

【问题讨论】:

  • NCo 可能使用了它已有的连接。如果名称相同,NCo 可能无法识别更改的用户名和密码。您可能需要向 DestinationManager 注册一堆目的地,并实施手动池,在查找要使用的目的地时考虑用户名。
  • 我为每个用户使用了不同的名称..仍然输入错误的密码并登录。
  • 我通过使用检查并发用户名和密码的 RfcCustomDestination 类解决了这个问题。 RfcDestination dest = RfcDestinationManager.GetDestination("SAPConnection"); RfcCustomDestination temp = dest.CreateCustomDestination(); temp.User = txt_user.Text; temp.Password = txt_password.Text;如果密码错误则Dest.ping报错。

标签: asp.net authentication saprfc sap-dotnet-connector


【解决方案1】:

这是 RfcCustomDestination 的一个用例。创建一个只有 AppServerHost、SystemNumber 等参数但 用户、密码、客户端和语言的 RfcDestination。这可以被视为“基地目的地”。

然后,对于登录到您的应用程序的每个最终用户,从“基本目标”创建一个新的 RfcCustomDestination 对象,您可以在其中混合当前用户的特殊参数用户、密码、客户端和语言。 (您可能通过向最终用户提示某种“登录对话框”来从最终用户那里获得这些信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多