Consume web services published on internet

2014-08-19
2014-09-08
1 2 > >> (Page 1 of 2)
  • Tony Girgenti

    Tony Girgenti - 2014-08-19

    Hello,

    Is it possible to use GNU Cobol to write a client that will consume web services published on the internet?

    Any help would be gratefully appreciated.

    Thanks,
    Tony

     
  • Brian Tiffin

    Brian Tiffin - 2014-08-19

    You mean like

    http://opencobol.add1tocobol.com/gnucobol/#how-do-i-use-gnu-cobol-for-cgi (with an eye toward the AJAX and jQuery blurbs?)

    The short answer is yes.

    If the link above doesn't lead to the right info, feel free to ask again. There are other samples in the FAQ as well, libcURL, etc.

    Cheers,
    Brian

     
  • Tony Girgenti

    Tony Girgenti - 2014-08-19

    Hello Brian.

    Thanks for your help.

    I think that is what I want to do except that your cgienvform.html is the client consuming the service of gnucobolcgi and I want to code my client in GNU Cobol.

    Thanks,
    Tony

     
  • Brian Tiffin

    Brian Tiffin - 2014-08-19

    Yeah, consuming...hmmm?

    COBOL, by and large isn't network aware, at least not from the reserved words side of things.

    You could spend a few minutes/hours wrestling with netcat, nc, and forcefudging things through files for READ, WRITE. That will work, but it might be hairpulling.

    libCURL, presents a pretty handy API. Short, steep learning curve, one or two functions later and it is just tweaking flags and names.

    There are socket read libraries available, ezaSockets, and native POSIX

    So, while the short answer is yes, the real answer is more verbose. ;-)

    Umm, take a look at http://opencobol.add1tocobol.com/gnucobol/#function-id

    The sample is a read-url function. Please note: this is working, yet incomplete; ideas into the ether, details may change

    Cheers,
    Brian

     
    Last edit: Brian Tiffin 2014-08-19
  • Tony Girgenti

    Tony Girgenti - 2014-08-19

    Brian,

    I have a consuming client working and I wrote it in Microsoft VS 2013 C# program.

    Can I call a C# program(.dll/.exe) to simply do the consuming and pass the data back to a GNU Cobol program for display and reporting?

    Thanks,
    Tony

     
    • Simon Sobisch

      Simon Sobisch - 2014-08-20

      Not very quick as CALLs from GNU Cobol are "native" with C only, not C++ and in no way C#.

      The quick and dirty way is using an exe-file, and

          CALL 'SYSTEM' using 'c#.exe some params "including text"'
          END-CALL
      

      if you have more things you want to pass write a LINE SEQUENTIAL FILE.
      The way back (despite of the RETURN CODE) would be a LINE SEQUENTIAL FILE.

      The better way would be using a c#.dll, writing a small C++ wrapper with external "C". This wrapper can be called via 'CALL' and you can pass data in both directions, see COBOL<->C.

      This would definitely be a worth entry for the FAQ if you document this with a small sample (COBOL --> [using C++ as a wrapper] --> C#). The other way (C# --> COBOL) is missing in the FAQ, too and likely goes down to import and call cob_resolve, then call the result. Feel free to write the necessary samples and docs, Brian Tiffin will surely add this to the FAQ when finished.

      Simon

       
      • Tony Girgenti

        Tony Girgenti - 2014-08-21

        Simon,

        Do you know how to do this?

        The better way would be using a c#.dll, writing a small C++ wrapper with external "C". This wrapper can be called via 'CALL' and you can pass data in both directions<<

        I would like to try it, but I don't know how to do it.

        Thanks,
        Tony

         
        • Simon Sobisch

          Simon Sobisch - 2014-08-21

          Sure I can help.
          What are the problems when following the steps linked above?

          Simon

           
          • Tony Girgenti

            Tony Girgenti - 2014-08-23

            Simon,

            I have this working:
            http://stackoverflow.com/questions/4139456/how-to-reuse-a-net-assembly-from-a-pure-c-application

            What does the output from the solution need to be to be called from an GNU Open COBOL program?

            Thanks,
            Tony

             
            • Simon Sobisch

              Simon Sobisch - 2014-08-23

              Assuming you have the wrapper program callable as C:

              • check that you have it declared as C_EXTERN (see the old wiki entry that I've linked before)

              • CALL 'SHARPWRAP' USING a-binary-long-if-you-want-to-pass-some-number maybe-a-binary-long-with-parameter-length-for-next-pic-x whatever-you-need-as-pic-x END-CALL

              If it doesn't work please a short sample code of both C# and wrapper. We will tweak and fix it until it works (and can be placed into the FAQ ;-).

              Simon

               
              • Tony Girgenti

                Tony Girgenti - 2014-08-25

                Simon,

                I have been trying to link my COBOL program to a 'C' object file using this command line: "cobc -x -o callcsl callcsl.cob projectctest.obj" and I am getting this error: "projectctest.obj:1: Error: Invalid indicator 'û' at column 7"

                When I build/compile my solution that has the ProjectCTest (plain ANSI 'C'), it gives warnings, not errors. I'm trying to get rid of the warnings to see if that will fix the problem.

                I know you want short sample code, but I will give you these files:

                -------------------- COBOL 2.0 program ---------------------

                        IDENTIFICATION DIVISION.
                        PROGRAM-ID. CallCSL.
                        ENVIRONMENT DIVISION.
                        DATA DIVISION.
                        WORKING-STORAGE SECTION.
                         01 VALUE-A USAGE BINARY-LONG.
                         01 VALUE-B USAGE BINARY-LONG.
                        PROCEDURE DIVISION.
                          CALL "ProjectCTest" USING VALUE-A VALUE-B
                      END-CALL. 
                          STOP RUN.
                

                ---------------- The plain ANSI 'C" program --------------

                #include "stdafx.h"
                #pragma comment(lib, "CPPCLibrary.lib") 
                
                #ifndef C_EXTERN
                #if defined (_WIN32) || defined (__CYGWIN__)
                #define C_EXTERN __declspec(dllexport) extern
                #else
                #define C_EXTERN extern
                #endif
                #endif
                C_EXTERN int;
                extern __declspec(dllimport) int MathAdd(int a, int b);
                int _tmain(int argc, _TCHAR* argv[])
                {
                    int answer = MathAdd(10, 32);
                    _tprintf(_T("%d\n"), answer);
                    while (8 == 8) {}
                    return 0;
                }
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                
                ------------ The C++ program (CPPCLibrary.h) ---------------
                
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                ::c++
                #pragma once
                using namespace System;
                namespace CPPCLibrary {
                
                extern "C" __declspec(dllexport) int MathAdd(int a, int b)
                
                {
                    return CSLibrary::Math::Add(a, b);
                    };
                }
                

                --------------------- The C# Program -----------------------

                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                ::csharp
                using System;
                using System.Collections.Generic;
                using System.Linq;
                using System.Text;

                namespace CSLibrary
                {
                static public class Math
                {
                static public int Add(int a, int b)
                {
                int c = a + b;
                return c;
                }
                }
                }
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                Of course you know that most of this came from here:
                http://stackoverflow.com/questions/4139456/how-to-reuse-a-net-assembly-from-a-pure-c-application

                Any help that you can provide to make this work would be gratefully appreciated.

                Thanks,
                Tony

                ModEdit: syntax highlighting added

                 
                Last edit: Simon Sobisch 2014-08-26
                • Vincent (Bryan) Coen

                  Need to add -free to cobc command line or add as first line of
                  Cobol source file starting in column 8

                  source free

                  At the moment the compiler thinks your programs is written as fixed format.

                  Vince

                   
                  Last edit: Simon Sobisch 2014-08-27
                  • Vincent (Bryan) Coen

                    Hmm editor seems to be removing the two greater thans signs..
                    ">>source free"

                    See if that is any better :(

                    Vince

                     
                    Last edit: Simon Sobisch 2014-08-26
                    • Tony Girgenti

                      Tony Girgenti - 2014-08-26

                      Vince,

                      I added this ">>SOURCE FORMAT IS FREE" to first line of CallCSL.cob starting in column 8 and got the same error:
                      "projectctest.obj:1: Error: Invalid indicator 'û' at column 7"

                      I also tried "cobc -free -x -o callcsl callcsl.cob projectctest.obj" and
                      "cobc -x -o callcsl -free callcsl.cob projectctest.obj" and got these warnings/errors:

                      projectctest.obj:2: Warning: Line not terminated by a newline
                      projectctest.obj:3: Warning: Line not terminated by a newline
                      projectctest.obj:4: Warning: Line not terminated by a newline
                      projectctest.obj:5: Warning: Line not terminated by a newline
                      projectctest.obj:6: Warning: Line not terminated by a newline
                      projectctest.obj:6: Error: syntax error, unexpected TOKEN, expecting '.'

                      Aren't those warnings/errors referring to projectest.obj?

                      Thanks,
                      Tony

                       
                      • Vincent (Bryan) Coen

                        In a nutshell yes, you are trying to compile through cobc callCSL.cob
                        AND projecttest.obj

                        Suggest you compile the C program first them compile the Cobol program
                        and link it with the o/p from the C compile.

                        Now I am guessing here :) try:

                        cobc -x callcsi cllcsi.cob -l project.o

                        The above is assuming you are using Linux so if using Windows the
                        extension for project may well be .obj.

                        Vince

                         
                        Last edit: Simon Sobisch 2014-08-27
                        • Tony Girgenti

                          Tony Girgenti - 2014-08-26

                          Vince,

                          ProjectCTest.c is compiled in Visual Studio to produce ProjectCTest.obj.

                          I thought this: "cobc -x -o callcsl callcsl.cob projectctest.obj" was compiling callcsl.cob and linking ProjectCTest.obj to it.

                          I'm confused.

                          Thanks,
                          Tony

                           
  • Vincent (Bryan) Coen

    What you are doing according to the cobc command line is compiling both
    files and the second is an object already so precede '-l' before the
    object module name as shown on my previous message.

    E.g., "cobc -x -o callcsl callcsl.cob -lprojectctest.obj"

    Well that's the way I see it :)

    Vince

     
    Last edit: Simon Sobisch 2014-08-27
    • Tony Girgenti

      Tony Girgenti - 2014-08-26

      Vince,

      I'm sorry for being mixed up about how to do this. I should learn to read more of the documentation and reading people's posts.

      I used this at the command line: "cobc -x -o callcsl callcsl.cob -lProjectCTest.obj"

      I now have this error:
      "ProjectCTest.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:ICF' specification"

      Thanks,
      Tony

       
      • Vincent (Bryan) Coen

        Err...

        I have absolutely no idea what that is about.

        I assume you are using a VC compiler and it is coming from the MS linker.

        Might be worth a search for the error # (LNK4075) on the MS website or
        online docs.

        Another possible is try leaving a space after '-l' and Projec....

        Don't know the MS linkers command syntax so totally guessing.

        Vince

         
        Last edit: Simon Sobisch 2014-08-27
        • Tony Girgenti

          Tony Girgenti - 2014-08-26

          Vince,

          I got by the LNK4075 error.

          I am now getting this error: "error LNK2005: _main already defined in cob18108_0.obj".

          Thanks,
          Tony

           
          • Simon Sobisch

            Simon Sobisch - 2014-08-27

            The main error is because you want your C program being a module, not a main. As it's a main (along with command line params) and the -x from cobc adds a main, too, you get the error.
            For being easy accessible from COBOL your module entry point should be named like the CALL you want to do, in your sample ProjectCTest and should take your ints like the CPP version does.

            .obj and .lib files should be passed to cobc without -l, cobc checks if it just has to link them or not. Same is true for .c files, therefore the following should work:

            cobc -x -v callcsl.cob projecttest.c
            

            Simon

             
            • Tony Girgenti

              Tony Girgenti - 2014-08-27

              Simon,

              I don't have a projectctest.c file.

              Thanks,
              Tony

               
          • Vincent (Bryan) Coen

            Well that one is clear.

            You have duplicate entry points called _main so rename the one in the C
            routine to the name of the routines you cannot alter the Cobol names.

            Vince

            Guessing by the way...

            On 27/08/14 00:56, Tony Girgenti wrote:

            Vince,

            I got by the LNK4075 error.

            I am now getting this error: "error LNK2005: _main already defined in
            cob18108_0.obj".

            Thanks,
            Tony


             
            • Tony Girgenti

              Tony Girgenti - 2014-08-27

              Vince,

              My entry point in my C program is "main", not "_main".

              Thanks,
              Tony

               
              • Vincent (Bryan) Coen

                Change 'main' to name of module and recompile and see what happens

                .

                On 27/08/14 14:26, Tony Girgenti wrote:

                Vince,

                My entry point in my C program is "main", not "_main".

                Thanks,
                Tony


                 
1 2 > >> (Page 1 of 2)


Anonymous

Cancel  Add attachments





Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks