Web Service Query

RobertbNZ

Member
Joined
Jun 26, 2020
Messages
5
Programming Experience
Beginner
I have spent some time working with the tutorial Create web APIs with ASP.NET Core as recommended in a previous query. I'm now trying to generate a client to invoke CICS web service JSPG2 but I'm having trouble with writing my API test. I suspect that I'm trying to approach the problem from the wrong end, and the tutorial's approach should be abandoned.

This diagram shows what I'm trying to achieve
WebAPI.jpg


I have software (Micro Focus) that provides COBOL and Mainframe support for our VB.Net software that generates COBOL for Web Services and other functions. Our software has generated program JSPG2, an operation within service MyJSv, that is invoked with JSON message IJSPG2, and responds with message OJSPG2. I'm trying to develop interface code represented on the diagram above as Interface MyJSv-JSPG2. My eventual plan is for our software to generate these interfaces from the CICS Web Service message definitions, but the current objective is to develop an interface manually so that I have a pattern to work from.

It was recommended that I follow this tutorial. Now I think that this tutorial shows me how to create a service. I don't want to create a web server, I want to create a web client.

If I'm right, please point me at the relevant tutorials for me to read.

If I'm wrong and the tutorial is the correct pattern, then I need to get past the current issues, putting the correct code into the POST object, and setting the endpoint address.
Either way your help will be greatly appreciated. Robert.

If we're continuing with the tutorial's approach: -
This is what I'd done: -

I generated an API project called MyJSv and created a controller for JSPG2 within this. I developed hierarchical classes IJSPG2.cs and OJSPG2.cs in the Models folder, matching the messages which start life as COBOL records on the server (mainframe) side. I added and registered a database context. So far so good.

Now I reached the tutorial stage Scaffold a Controller. Like the tutorial I used "API Controller with actions, using Entity Framework", and in the dialog selected: -
Model Class IJSPG2 (MyJSv.Models)
Data Context Class: JSPG2Context (MyJSv.Models)

Visual Studio reacted with an error: -
There was an error running the selected code generator:
The entity type 'IJSPG2' requires a primary key to be defined.
If you intended to use a keyless enitity type call 'HasNoKey0'
Discussion (this was originally posted to the .NET CORE forum on the VB.NET Community) led me to realize that I should be using "API Controller with actions". This got past the error, but left me wondering what to do next.

The tutorial's POST code within TodoItemsController (derived from ControllerBase), which was generated using API Controller with Actions Using Entity Framework, and then slightly modified, was
C#:
        // POST: api/TodoItems
        [HttpPost]
        public async Task<ActionResult<TodoItem>> PostTodoItem(TodoItem todoItem)
        {
            _context.TodoItems.Add(todoItem);
            await _context.SaveChangesAsync();

            //return CreatedAtAction("GetTodoItem", new { id = todoItem.Id }, todoItem);
            return CreatedAtAction(nameof(GetTodoItem), new { id = todoItem.Id }, todoItem);
        }
The equivalent code within MyJSvController, also derived from ControllerBase but generated using API Controller with actions, is
C#:
        // POST api/<JSPG2Controller>
        [HttpPost]
        public void Post([FromBody] string value)
        {
        }
This is quite different, so what do I write here? What it needs to do is to convert the C# class IJSPG2 to JSON, send this to the endpoint (http://localhost:9003/cics/services/JSPG2), and process the response from JSON to OJSPG2. I'm guessing that this is what
C#:
 return CreatedAtAction(nameof(GetTodoItem), new { id = todoItem.Id }, todoItem);
does, but I'm struggling to understand the tutorial code and the web resources that I've found so far pre-date .NET CODE 3.1 (which is a prerequisite for the tutorial) or are incomprehensible to me (I am learning C#, Web API, and .NET CORE all at once, after ~15 years with VB.NET and ASP.NET).
 

RobertbNZ

Member
Joined
Jun 26, 2020
Messages
5
Programming Experience
Beginner
Can somebody help me with this please? It's been well over a week with no replies, and I really need to make progress with this: I'm running out of other things to work on in the meantime.

I have a test web service running at http://localhost:9003/cics/services/JSPG2 that accepts JSON input that is described by class IJSPG2, and produces output (class OJSPG2). I want to know how to write a client program, either Windows or Web, that will
  1. Format class IJSPG2 to JSON, and send this to the service
  2. Receive the JSON response and put the data values into class OJSPG2
Details of this issue, and what I've tried to do so far, are above.
 
Top Bottom