本文介绍了如何从ASP.NET调用AS / 400 RPG程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家。

我的目标是通过ASP调用一个CL程序(在AS400中)并返回结果。

我在 []。但它没有详细说明有关CL程序的任何内容。



如文章中所述,我创建了AS400Program.cs类,





Hi experts.
My aim is to call through ASP a CL program (in AS400) and return the result.
I have fount a nice article about this at Calling AS/400 (AS400) RPG Programs From ASP.NET[^] . But it does not elaborates anything regarding CL program.

As given in the article, I have created the class AS400Program.cs,


using System;

namespace Interfaces.Source
{
    /// <summary>
    /// Summary description for AS400Program.
    /// </summary>
    public class AS400Program
    {
        private bool as400Configured = false;
        private cwbx.AS400System as400;
        private cwbx.Program program;

        // configuration format:
        // as400;userid;password;library;program
        public AS400Program(string configuration)
        {
            if(!as400Configured)
            {
                string[] settings = configuration.Split(';');
                if(settings.Length == 5)
                {
                    as400 = new cwbx.AS400SystemClass();
                    program = new cwbx.Program();

                    as400.Define(settings[0]);
                    program.system = as400;
                    program.system.UserID = settings[1];
                    program.system.Password = settings[2];
                    program.LibraryName = settings[3];
                    program.ProgramName = settings[4];
                    as400Configured = true;
                }
                else
                {
                    throw(new Exception(
                        string.Format("Invalid AS400Program configuration string : [{0}]", configuration)));
                }
            }
        }

        public bool Invoke(bool throwInsteadOfReturn, ref cwbx.ProgramParameters parameters)
        {
            bool success = false;

            try
            {
                if(as400.IsConnected(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd) == 0)
                {
                    //  Lost connection with the AS400.  Disconnect, then reconnect.
                    as400.Disconnect(cwbx.cwbcoServiceEnum.cwbcoServiceAll);
                    as400.Connect(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd);

                    if(as400.IsConnected(cwbx.cwbcoServiceEnum.cwbcoServiceRemoteCmd) == 0)
                    {
                        //  Log something here.
                    }
                }

                program.Call(parameters);
                success = true;
            }
            catch(Exception e)
            {
                // Capture to log the errors but then re-throw it to let caller know there was trouble.
                if(as400.Errors.Count > 0)
                {
                    foreach(cwbx.Error error in as400.Errors)
                    {
                        //  Log something here.
                    }
                }

                if(program.Errors.Count > 0)
                {
                    foreach(cwbx.Error error in program.Errors)
                    {
                        //  Log something here.
                    }
                }

                if(throwInsteadOfReturn)
                {
                    throw(e);
                }
            }

            return(success);
        }

        public void Close()
        {
            as400.Disconnect(cwbx.cwbcoServiceEnum.cwbcoServiceAll);
        }
    }
}





和功能类似:





And the function similarly:

//  Assume the RPG program being called takes one input paramater, PartId, and returns the PartPrice.

protected enum DataLengths : int
{
    PartId     = 12,
    PartPrice  = 15,
}


string partId = "3001891A";  // hardcoded for this example


AS400Program program = new AS400Program(ConfigurationSettings.AppSettings["partsPricingConfig"]);


cwbx.StringConverter stringConverter = new cwbx.StringConverterClass();
cwbx.PackedConverter packedConverter = new cwbx.PackedConverterClass();
packedConverter.DecimalPosition = 4;
packedConverter.Digits = (int)DataLengths.PartPrice;

cwbx.ProgramParameters parameters = new cwbx.ProgramParametersClass();

parameters.Append("PartId", cwbx.cwbrcParameterTypeEnum.cwbrcInout, (int)DataLengths.PartId);
stringConverter.Length = (int)DataLengths.PartId;
parameters["PartId"].Value = stringConverter.ToBytes(partId.PadRight((int)DataLengths.PartId, ' '));

parameters.Append("PartPrice", cwbx.cwbrcParameterTypeEnum.cwbrcInout, (int)DataLengths.PartPrice);
parameters["PartPrice"].Value = packedConverter.ToBytes("0");

program.Invoke(true, ref parameters);

string price = packedConverter.FromBytes(parameters["PartPrice"].Value);

program.Close();

return(Double.Parse(price));





我需要知道在哪里调用CL程序,并使用函数返回的价格值。

任何信息关于这一点将不胜感激。 :)



I need to know where to call the CL program, and use the price value returned from the function.
Any info regarding this will be appreciated. :)

推荐答案


program.Invoke(true, ref parameters);

调用我们在appsettings声明的程序(从

invokes the program that we declare at appsettings (read connection from

AS400Program(ConfigurationSettings.AppSettings["partsPricingConfig"]);



这篇关于如何从ASP.NET调用AS / 400 RPG程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 23:49