如何通过 Host-Initiated 处理使用持久连接

持久连接是指在特定调用结束后仍保持打开状态的连接。 由于应用程序不需要在每个调用中重新创建连接,因此可以使用持久连接来提高主机启动的应用程序的效率。 使用与主机发起的处理(HIP)的持久连接的应用程序以与 Windows-Initiated 处理(WIP)相同的方式运行。 当然,区别在于大型机启动并终止连接,而 Windows 应用程序响应大型机的请求。

注释

主机集成服务器支持与 WIP 相同的许多 HIP 编程环境。 例外是 IMS Connect、分布式程序调用(DPC)和 SNALink,而 HIP 持久连接不支持这些连接。

将持久连接与 HIP 配合使用

  1. 从大型机向您的 Windows 应用程序接收来电,表明已建立连接。

    大型机应用程序负责请求持久连接。

  2. 让 Windows 应用程序以相关方式响应请求。

    您的应用程序无需执行任何特定操作即可使用持久连接:创建和终止连接是大型机应用程序的责任。

  3. (可选)可以创建 HIPServerUserContext 的新实例来查询连接的状态。

    使用相关连接的上下文信息自动创建新实例。 使用 HIPServerUserConext,可以确定大型机创建的连接类型,并相应地做出反应。

示例:

以下代码是从 SDK 中的 CICS 示例应用程序拉取的。 此示例使用服务器对象的CONNTYPE来执行不同的动作。

decimal GetAccountBalance(object[] contextArray)  
        {  
            decimal ReturnBalance = 0.0m;  
            string ConnType;  
            object contextValue;  
  
            _TIServerContext.ReadContext("CONNTYPE", out contextValue, ref contextArray);  
  
            if (contextValue == null)  
                ReturnBalance = 123.45m;  
            else  
            {  
                ConnType = contextValue.ToString();  
                ConnType.ToUpper();  
                switch (ConnType)  
                {  
                    case "OPEN":  
 // Set the initial value of the Account Balance  
 // and save it in a global varaible and return it.  
                        ReturnBalance = 123.45m;  
                        _AccountBalance = ReturnBalance;  
                        break;  
  
                    case "USE":  
 // Increase the value of the global Account Balance  
 // varaible and return its value. Save this new value  
 // in the global variable for later use  
                        _AccountBalance += 100;  
                        ReturnBalance = _AccountBalance;  
                        break;  
  
                    case "CLOSE":  
 // Increase the value of the global Account Balance  
 // variable and return the new value. Set the global variable  
 // to zero because the "CLOSE" call indicates that we are   
 // done with it.  
                        ReturnBalance = _AccountBalance + 150;  
                        _AccountBalance = 0.0m;  
                        break;  
  
                    case "UNKNOWN":  
                    default:  
                        _AccountBalance = 0.0m;  
                        ReturnBalance = 123.45m;  
                        break;  
                }  
            }  
  
            return ReturnBalance;  
        }  

该代码示例使用全局变量来存储信息。 还可以使用上下文对象本身来存储信息。 虽然此处未显示,但可以使用上下文对象将信息传回 Windows 应用程序。

另请参阅

持久连接