當您連線到會話整合器的 LU0 工作階段時,必須執行的第一個動作是建立和初始化 Microsoft.HostIntegration.SNA.Session.SessionLU0 物件。 顧名思義, Microsoft.HostIntegration.SNA.Session.SessionLU0 代表應用程式的 LU0 工作階段,而且是您用來存取 SNA 網路的主要介面。
初始化連線之後,您就可以開始透過 LU0 工作階段傳送和接收資訊。
初始化 LU0 的工作階段整合器
判斷您要連線的會話類型。
如有必要,請使用
Microsoft.HostIntegration.SNA.Session.SessionConnectionLU0建立新的會話連線。如果您有所有相關信息,您可以直接建立
Microsoft.HostIntegration.SNA.Session.SessionConnectionLU0。 不過,您不需要執行此步驟。 更可能,您只會在步驟 3 中傳入 LU 連接字串。使用
Microsoft.HostIntegration.SNA.Session.SessionLU0建立新的工作階段。將連線資訊傳遞至
Microsoft.HostIntegration.SNA.Session.SessionLU0.Connect%2A。Connect包含數個多載:您可以選擇使用已建立Microsoft.HostIntegration.SNA.Session.SessionConnection的物件、Microsoft.HostIntegration.SNA.Session.SessionConnection物件和其他初始化資訊,或使用連接字串和初始化資訊進行連線。如果您選擇使用連接字串進行呼叫
Microsoft.HostIntegration.SNA.Session.SessionLU0.Connect%2A,工作階段整合器會為您建立新的Microsoft.HostIntegration.SNA.Session.SessionConnectionLU0。 您可以透過Microsoft.HostIntegration.SNA.Session.SessionLU0.Connection%2A直接存取Microsoft.HostIntegration.SNA.Session.SessionConnectionLU0物件。如有必要,請使用
Microsoft.HostIntegration.SNA.Session.SessionLU0.IsConnected%2A確認您已連線。
範例
下列程式代碼範例示範如何使用使用者收到的連接字串來建立會話。
private void CreateSession_Click(object sender, EventArgs e)
{
try
{
LUName.Text = LUName.Text.Trim();
if (LUName.Text.Length == 0)
{
MessageBox.Show("You must fill out the LU or Pool Name");
return;
}
_session = new SessionLU0(); _session.Connect("LogicalUnitName=" + LUName.Text, SessionLU0InitType.SSCP);
// Receive the logon screen.
SessionLU0Data receivedData = _session.Receive(20000, true);
// Trace out the received data.
TraceData(false, receivedData.Data, receivedData.Indication);
// Disable every button and text box.
DisableEverything();
// Insert User/Password.
EnableInsertUserId();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
請注意,此程式代碼範例的主要用途是建立新的會話,並使用連接字串連線到 LU。 不過,此範例也會在 LU0 工作階段接收回傳的數據。 此範例也會使用 EnableInsertUserId 函式傳送密碼資訊。