SAP Hard-coded logon parameters not allowed when using a Destination Configuration in C#

℡╲_俬逩灬. 提交于 2019-12-06 05:37:15

Check this out. This is a just a demo code.

public class Program
{
    static void Main(string[] args)
    {
        SapConnection con = new SapConnection();
        RfcDestinationManager.RegisterDestinationConfiguration(con);
        RfcDestination dest = RfcDestinationManager.GetDestination("NSP");
        RfcRepository repo = dest.Repository;

        IRfcFunction fReadTable = repo.CreateFunction("ZSOMA");
        fReadTable.SetValue("I_NRO1", 1);
        fReadTable.SetValue("I_NRO2", 2);


        fReadTable.Invoke(dest);
        var result = fReadTable.GetValue("E_RESULT");

        Console.WriteLine(result.ToString());
        Console.ReadLine();
    }
}

public class SapConnection : IDestinationConfiguration
{
    public RfcConfigParameters GetParameters(string destinationName)
    {
        RfcConfigParameters conf = new RfcConfigParameters();
        if (destinationName == "NSP")
        {
            conf.Add(RfcConfigParameters.AppServerHost, "sap-vm");
            conf.Add(RfcConfigParameters.SystemNumber, "00");
            conf.Add(RfcConfigParameters.SystemID, "xxx");
            conf.Add(RfcConfigParameters.User, "yourusername");
            conf.Add(RfcConfigParameters.Password, "yourpassword");
            conf.Add(RfcConfigParameters.Client, "001");
        }
        return conf;
    }

    public bool ChangeEventsSupported()
    {
        return true;
    }

    public event RfcDestinationManager.ConfigurationChangeHandler ConfigurationChanged;
}

I would prompt the user for the password in this case. I would use a dialog box that masks the text with a password character.

Dim value As String

value = InputBox("Security Check", " Enter password", "*")

objParameter.Add(RfcConfigParameters.Password, Convert.ToString(value))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!