如何从ASP.NET调用AS / 400 RPG程序 [英] How to call a AS/400 RPG Programs From ASP.NET

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

问题描述

嗨专家。

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

我在从ASP.NET调用AS / 400(AS400)RPG程序 [ ^ ]。但它没有详细说明有关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. :)

推荐答案

自从我把RPG和CL算作我的朋友以来已经太久了 - 但我发现这篇文章展示了如何调用CL程序参数成功...



不确定它是否会有所帮助 [ ^ ]
It''s been far too long since I counted RPG and CL as my friends - but I found this post which shows how to call a CL program with parameters successfully...

Not sure if it will help [^]


搞定了。

Got it.
program.Invoke(true, ref parameters);

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

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

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


AS400是一项非常古老的技术,我不喜欢对它有很多想法。但搜索后我发现了以下文章。你可以检查一下。这可能会对您有所帮助。

http://www.netsplore.com/PublicPortal /Default.aspx?tabid=246 [ ^ ]

ASP中的AS400数据连接。 NET [ ^ ]





--Amit
AS400 is very old technology and I don''t have much idea about it. But after searching I came across the following articles. You can check it. This may help you.
http://www.netsplore.com/PublicPortal/Default.aspx?tabid=246[^]
AS400 Data Connection in ASP.NET[^]


--Amit


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆