param.Option);inputTable.SetValue("33"

时间:2021-09-01 04:59:37

按照差此外需求,安置差别位数的 Rfc SDK

param.Option);inputTable.SetValue("33"

1.结构 Sap Adress Information,且担任 IDestinationConfiguration

public class SapAddressInfo : IDestinationConfiguration { public string SapHostIp { get; set; } public string SapSystemNumber { get; set; } public string SapUserAccount { get; set; } public string SapUserPassword { get; set; } public string SapClient { get; set; } public string SapLanguage { get; set; } public string SapPoolSize { get; set; } public string SapPeakConnectionsLimit { get; set; } public string SapConnectionIdleTimeout { get; set; } public string DestinationName { get; set; } RfcConfigParameters IDestinationConfiguration.GetParameters(string destinationName) { var parms = new RfcConfigParameters(); if (destinationName.Equals(DestinationName)) { parms.Add(RfcConfigParameters.AppServerHost, SapHostIp); //SAP主机IP parms.Add(RfcConfigParameters.SystemNumber, SapSystemNumber); //SAP实例 //通信账户 用户名 oms 暗码123456 parms.Add(RfcConfigParameters.User, SapUserAccount); //用户名 parms.Add(RfcConfigParameters.Password, SapUserPassword); //暗码 parms.Add(RfcConfigParameters.Client, SapClient); // Client parms.Add(RfcConfigParameters.Language, SapLanguage); //登陆语言 parms.Add(RfcConfigParameters.PoolSize, SapPoolSize); parms.Add(RfcConfigParameters.PeakConnectionsLimit, SapPeakConnectionsLimit); parms.Add(RfcConfigParameters.ConnectionIdleTimeout, SapConnectionIdleTimeout); } return parms; } public bool ChangeEventsSupported() { return false; } event RfcDestinationManager.ConfigurationChangeHandler IDestinationConfiguration.ConfigurationChanged { // ReSharper disable once ValueParameterNotUsed add { } // ReSharper disable once ValueParameterNotUsed remove { } } }

  2.创建一个Sap连接的处事接口

public interface ISapConnection { RfcDestination Destination { get; set; } void Open(); void Dispose(); }

  3.接下来我们对接口进行实现

public class SapConnection : IDisposable, ISapConnection { private const string SapHostIpName = "SapHostIpName"; private const string SapSystemNumberName = "SapSystemNumberName"; private const string SapUserAccountName = "SapUserAccountName"; private const string SapUserPasswordName = "SapUserPasswordName"; private const string SapClientName = "SapClientName"; private const string SapLanguageLanguage = "SapLanguageLanguage"; private const string SapPoolSizeName = "SapPoolSizeName"; private const string SapPeakConnectionsLimitName = "SapPeakConnectionsLimitName"; private const string SapConnectionIdleTimeoutName = "SapConnectionIdleTimeoutName"; private const string DestinationName = "DestinationName"; public SapConnection(Object settingsManager) { if (settingsManager == null) throw new ArgumentNullException(nameof(settingsManager)); //自行赋值 var sapHostIp = "SapHostIpName"; var sapSystemNumber = "SapSystemNumberName"; var sapUserAccount = "SapUserAccountName"; var sapUserPassword = "SapUserPasswordName"; var sapClient = "SapClientName"; var sapLanguage = "SapLanguageLanguage"; var sapPoolSize = "SapPoolSizeName"; var sapPeakConnectionsLimit = "SapPeakConnectionsLimitName"; var sapConnectionIdleTimeout = "SapConnectionIdleTimeoutName"; var destinationName = "DestinationName"; SapAddressInfo = new SapAddressInfo { SapHostIp = sapHostIp, SapSystemNumber = sapSystemNumber, SapUserAccount = sapUserAccount, SapUserPassword = sapUserPassword, SapClient = sapClient, SapLanguage = sapLanguage, SapPoolSize = sapPoolSize, SapPeakConnectionsLimit = sapPeakConnectionsLimit, SapConnectionIdleTimeout = sapConnectionIdleTimeout, DestinationName = destinationName/*"ECQ"*/ }; if (!RfcDestinationManager.IsDestinationConfigurationRegistered()) { RfcDestinationManager.RegisterDestinationConfiguration(SapAddressInfo); } } public SapAddressInfo SapAddressInfo { get; set; } public RfcDestination Destination { get; set; } public void Open() { try { Destination = RfcDestinationManager.TryGetDestination(SapAddressInfo.DestinationName); if (Destination == null) { if (!RfcDestinationManager.IsDestinationConfigurationRegistered()) { RfcDestinationManager.RegisterDestinationConfiguration(SapAddressInfo); } Destination = RfcDestinationManager.GetDestination(SapAddressInfo.DestinationName); } } catch (Exception ex) { throw new Exception("An exception occurred when trying to open a SapConnection. Check inner exception for details.", ex); } } public void Dispose() { //RfcDestinationManager.UnregisterDestinationConfiguration(SapAddressInfo); if (SapAddressInfo != null) { try { RfcDestinationManager.UnregisterDestinationConfiguration(SapAddressInfo); } catch (Exception ex) { Trace.TraceError("An error occurred when trying to unregister destination configuration. Exception: {0}", ex); } } GC.SuppressFinalize(this); } }

  

4.这样你就可以使用这个接口进行连接了