-->

c# Cannot create EBCDIC file on Unisys Mainframe W

2019-08-12 14:49发布

问题:

I am attempting to upload data generated by users on asp.net site to a Unisys mainframe. My client decided that they want me to load the data directly onto a Unisys Mainframe windows share instead of using FTP to upload the file. FTP typically does the conversion between ASCII and EBCDIC.

The problem is that the mainframe sees the file as ASCII regardless of whether I've encoded the file contents as EBCDIC.

The test code is here:

        string dataToWrite = "ACHR0000000000575TEST EBCDICPAYEE             8899007500038159 0000001000160330 ".ToUpper();
        Encoding ebcdic = Encoding.GetEncoding("IBM037");

        List<byte> bytes = new List<byte>();
        bytes.AddRange(Encoding.Convert(Encoding.ASCII, ebcdic, Encoding.ASCII.GetBytes(dataToWrite)));


        using (var unc = new UNCAccessWithCredentials())
        {
            // get access to the reconciliation file share using credentials in the config
            string path = @"\\xxx\RECONDEV";
            unc.NetUseWithCredentials(path, "XXX","", "XXX");
            string fileName = Path.Combine(path, "ACH");
            using (var binWriter = new BinaryWriter(File.OpenWrite(fileName)))
            {
                binWriter.Write(bytes.ToArray());
                binWriter.Flush();
                binWriter.Close();
            }
        }

Questions
1) Should I create the file as ASCII and then have the mainframe job call a utility to convert the file EBCDIC? If so, what is the name of the utility? The mainframe ops don't know of one.

2) Is there some way to actually create an EBCDIC file within .net? The EBCDIC encoding is working but I believe the file types are different and I have not been able to find out anything.

I literally haven't done anything with a mainframe in 2 decades so I am out of my depth.

Thanks in advance. Chris

回答1:

Just FYI, a consultant suggested we use a utility called MCPCopy to copy and convert the files from an ASCII stream to EBCDIC as we copied the file to the mainframe share. The utility can be installed as part of the NXExtend. The command line used by the ASP.Net site is:

c:\Windows\MCPCopy.exe {SourceFile} {DestinationFile} /Y /Z:SR /D:80

Hope this helps



标签: c# ebcdic