如何将持久连接与 Host-Initiated 处理配合使用
持久连接是在特定调用持续时间后保持打开状态的连接。 由于应用程序不需要在每次调用时重新创建连接,因此可以使用持久连接来提高主机启动的应用程序的效率。 使用与主机启动的处理 (HIP) 的持久连接的应用程序的工作方式与 Windows-Initiated 处理 (WIP) 的方式相同。 当然,区别在于大型机启动并终止连接,而 Windows 应用程序响应大型机的请求。
注意
主机集成服务器支持许多与 WIP 相同的 HIP 编程环境。 例外是 IMS Connect、分布式程序调用 (DPC) 和 SNALink,它们不支持 HIP 持久连接。
将持久连接与 HIP 配合使用
从大型机接收 Windows 应用程序的调用,指示已创建连接。
大型机应用程序负责请求持久连接。
让 Windows 应用程序以相关方式响应请求。
应用程序无需执行任何特定操作才能使用持久连接:创建和终止连接由大型机应用程序负责。
(可选)可以创建 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 应用程序。