在 C# 中使用目标配置时不允许使用 SAP 硬编码登录参数 [英] SAP Hard-coded logon parameters not allowed when using a Destination Configuration in C#

查看:96
本文介绍了在 C# 中使用目标配置时不允许使用 SAP 硬编码登录参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试动态连接到 SAP 服务器时,出现类似

When i try to connect to SAP server dynamically I am getting error like

使用目标配置时不允许使用硬编码的登录参数

Hard-coded logon parameters not allowed when using a Destination Configuration

任何人请帮助我

我需要从代码隐藏动态发送所有参数,而不是从 Web.config 发送

I need to send all parameters from codebehind Dynamically not from Web.config

从 web.config 它工作正常.. 但不是这里

from web.config its working fine .. but not here

我的代码是这样的

            SAPSystemConnect objSapConfig = new SAPSystemConnect();
            RfcDestination objSapdestination = null;

            RfcDestinationManager.RegisterDestinationConfiguration(objSapConfig);

            RfcConfigParameters objParameter = new RfcConfigParameters();
            objParameter.Add(RfcConfigParameters.AppServerHost, Convert.ToString("XXX"));
            objParameter.Add(RfcConfigParameters.Client, Convert.ToString("XXX"));
            objParameter.Add(RfcConfigParameters.Password, Convert.ToString("XXX"));
            objParameter.Add(RfcConfigParameters.SystemNumber, Convert.ToString("XXX"));
            objParameter.Add(RfcConfigParameters.User, Convert.ToString("XXX"));
            objParameter.Add(RfcConfigParameters.Language, Convert.ToString("XXX"));
            objParameter.Add(RfcConfigParameters.LogonGroup, Convert.ToString("XXX"));

            objParameter.Add(RfcConfigParameters.PoolSize, Convert.ToString("XXX"));
            objParameter.Add(RfcConfigParameters.PeakConnectionsLimit, Convert.ToString("5"));
            objParameter.Add(RfcConfigParameters.IdleTimeout, Convert.ToString("XXX"));
            //objParameter.Add(RfcConfigParameters.Name, Convert.ToString("XXX"));



            objSapdestination = RfcDestinationManager.GetDestination(objParameter);
            RfcCustomDestination customDest = objSapdestination.CreateCustomDestination();
            IRfcFunction func = customDest.Repository.CreateFunction("XXX");




            RfcRepository objSapRepository = objSapdestination.Repository;

            // Calling Sap Function
            IRfcFunction objSapDataFunction = objSapRepository.CreateFunction(Convert.ToString("XXX"));

            objSapDataFunction.SetValue("XXX", "XXX");

            objSapDataFunction.Invoke(objSapdestination);

            // Filling SapData into Table
            IRfcTable objSapTable = objSapDataFunction.GetTable(Convert.ToString("GIT_DATA"));

推荐答案

看看这个.这只是一个演示代码.

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

这篇关于在 C# 中使用目标配置时不允许使用 SAP 硬编码登录参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆