SAP 连接器 3.0 - 如何注销?

SAP Connector 3.0 - how to logout?

我想将不同的 SAP 用户保存到数据库中,并使用 SAP 登录名检查输入是否正确。对于登录,我必须使用 SAP.net Connector3.0.

过程:点击按钮->输入用户1->SAP登录->如果正确:保存,否则错误消息->SAP注销->再次点击按钮->输入用户2->SAP登录->...等等在

我的代码:

Private Sub ButtonSaveUser_Click(sender As Object, e As EventArgs) Handles ButtonSaveUser.Click

    Try
        Dim parms As New RfcConfigParameters
        parms.Add(RfcConfigParameters.User, TextBoxUser.Text)
        parms.Add(RfcConfigParameters.AppServerHost, TextBoxRouter.Text)
        parms.Add(RfcConfigParameters.SystemNumber, TextBoxSystemnumber.Text)
        parms.Add(RfcConfigParameters.SystemID, TextBoxSystem.Text)
        parms.Add(RfcConfigParameters.Password, TextBoxPasswort.Text)
        parms.Add(RfcConfigParameters.Client, TextBoxClient.Text)
        parms.Add(RfcConfigParameters.Language, TextBoxLanguage.Text)
        parms.Add(RfcConfigParameters.Name, "Connection Name")

        Dim dest As RfcDestination = RfcDestinationManager.GetDestination(parms)
        Dim repo As RfcRepository = dest.Repository

'在这个space中是我保存用户信息的部分。这有效。

    Catch ex As Exception
        MsgBox("Logon failed.  " + ex.Message)
    End Try
End Sub

问题:我必须在代码末尾写什么才能注销或断开连接? 我以为可能会有类似 'dest.disconnect' 命令的东西,但我找不到这样的命令。

(我的问题是,我是编程新手,不知道如何实现缺失的部分。)

如果有人可以 post 一个 vb 代码或提供任何其他信息,那就太棒了! 谢谢:)

我从来没有打扰过。我让目标管理器管理连接。 但是可以选择注销目的地。 你可以试试

public static void UnregisterDestinationConfiguration(IDestinationConfiguration config)

但我的印象是会话管理器应该管理一些事情,例如:
已编辑以反映评论

   var parms = new RfcConfigParameters();
   // the connection params are set .....
   //parms.xxx = 
   RfcDestination _dest;
   _dest = RfcDestinationManager.GetDestination(parms);

   IRfcFunction func = _dest.Repository.CreateFunction("Z_MY FUNC"); 
 RfcSessionManager.BeginContext(_dest);
 func.Invoke(_dest);
 RfcSessionManager.EndContext(_dest);

我的观点更多是对比登录版本和会话管理器为您管理的目的地。

我用下面的代码解决了我的问题:

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports SAP.Middleware.Connector

Public Class Form
Public Sub Buttonsaveuser_Click(sender As Object, e As EventArgs) Handles Buttonsaveuser.Click
    Dim objDestConfig As New InMemoryDestinationConfiguration
    Try
        Dim parms As New RfcConfigParameters
        parms(RfcConfigParameters.User) = TextBoxUser.Text
        parms(RfcConfigParameters.AppServerHost) = TextBoxRouter.Text
        parms(RfcConfigParameters.SystemNumber) = TextBoxSystemnumber.Text
        parms(RfcConfigParameters.SystemID) = TextBoxSystem.Text
        parms(RfcConfigParameters.Password) = TextBoxPasswort.Text
        parms(RfcConfigParameters.Client) = TextBoxClient.Text
        parms(RfcConfigParameters.Language) = TextBoxLanguage.Text
        parms(RfcConfigParameters.Name) = TextBoxDestination.Text

        RfcDestinationManager.RegisterDestinationConfiguration(objDestConfig)
                    objDestConfig.AddOrEditDestination(parms)

                    Dim destination1 As RfcDestination = RfcDestinationManager.GetDestination(TextBoxDestination.Text)
        destination1.Ping()



    Catch ex As Exception
        MsgBox("Logon failed.  " + ex.Message)
    Finally
                RfcDestinationManager.UnregisterDestinationConfiguration(objDestConfig)
        objDestConfig.RemoveDestination(TextBoxDestiantion.Text)
    End Try
End Sub

End Class







Public Class InMemoryDestinationConfiguration
Implements IDestinationConfiguration
    Private availableDestinations As Dictionary(Of String, RfcConfigParameters)

Public Sub New()
    availableDestinations = New Dictionary(Of String, RfcConfigParameters)()
End Sub

Public Function GetParameters(ByVal destinationName As String) As RfcConfigParameters _
    Implements IDestinationConfiguration.GetParameters
            Dim foundDestination As RfcConfigParameters = Nothing
    availableDestinations.TryGetValue(destinationName, foundDestination)
    Return foundDestination
End Function

Public Function ChangeEventsSupported() As Boolean _
    Implements IDestinationConfiguration.ChangeEventsSupported
            Return True 
End Function

Public Event ConfigurationChanged As RfcDestinationManager.ConfigurationChangeHandler _
    Implements IDestinationConfiguration.ConfigurationChanged


Public Sub AddOrEditDestination(ByVal parameters As RfcConfigParameters)
            Dim name As String = parameters(RfcConfigParameters.Name)

    If availableDestinations.ContainsKey(name) Then
        Dim EventArgs As New RfcConfigurationEventArgs(RfcConfigParameters.EventType.CHANGED, parameters)
        RaiseEvent ConfigurationChanged(name, EventArgs)
    End If

            availableDestinations(name) = parameters
    Dim tmp As String = "Application server"
    Dim isLoadValancing As Boolean = parameters.TryGetValue(RfcConfigParameters.LogonGroup, tmp)
    If isLoadValancing Then
        tmp = "Load balancing"
    End If

End Sub

Public Sub RemoveDestination(ByVal name As String)

    If availableDestinations.Remove(name) Then

        RaiseEvent ConfigurationChanged(name, New RfcConfigurationEventArgs(RfcConfigParameters.EventType.DELETED))

    End If
End Sub
end class