Resolved Web Service Query

RobertbNZ

Active member
Joined
Jun 26, 2020
Messages
34
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

Active member
Joined
Jun 26, 2020
Messages
34
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.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
2,120
Location
Chesapeake, VA
Programming Experience
10+
It would help us help you is you showed us the classes IJSPG2 and OJSPG2, because, quite frankly, I tried going to your company's website pages that you've linked in the past and can't seem to find a "developers guide" as to how use your company's product/services.

I'm sorry if the information is in the videos. I prefer to read rather than watch videos.
 

RobertbNZ

Active member
Joined
Jun 26, 2020
Messages
34
Programming Experience
Beginner
It would help us help you is you showed us the classes IJSPG2 and OJSPG2, because, quite frankly, I tried going to your company's website pages that you've linked in the past and can't seem to find a "developers guide" as to how use your company's product/services.

I'm sorry if the information is in the videos. I prefer to read rather than watch videos.
Skydiver, thanks for responding.

I wouldn't have thought you needed this much understanding of my software to answer my question, as the diagram above shows what I'm trying to do. Remember that program JSPG2 and messages IJSPG2 and OJSPG2 are a particular example, and my objective in developing a client that invokes JSPG2 by posting message IJSPG2, and handling the respond of OJSPG2, is to give me an example that I can generate from a the definition of program JSPG2. The class definitions that I'm currently working with have been manually prepared from the .json layouts: here is the input as displayed by SOAPUI Pro, followed by the output. I have expressed these as C# classes, roughly as we discussed in my Previous question, which you answered. The point of all this is that many data rules are NOT expressed in the .json but can be inferred from the program rules, such as "An update must follow an enquiry", and it should be relatively easy for me to express these rules in the get and set properties of the class. If you REALLY want to understand the wider context, I'd recommend that you watch MANASYS and Micro Focus from about 1 minute for about 30 seconds, and understand that ALL the rules I need are implied in the Jazz-format message definition shown there (pause when you reach this). I'll send you a link tomorrow to more information, to avoid the the need to view a video (but it's only 2 minutes) but I have to go now. Thanks for helping.

INPUT
JSON:
{
   "JSPG2" : {
      "IJSPG2" : {
         "JZ_Function" : "E",
         "JZ_Employee_Skip" : 0,
         "JZ_Employee" : {
            "EMPNO" : "90",
            "FIRSTNME" : "",
            "MIDINIT" : "",
            "LASTNAME" : "",
            "WORKDEPT" : "",
            "PHONENO" : "",
            "HIREDATE" : "",
            "JOB" : "",
            "EDLEVEL" : "",
            "SEX" : "",
            "BIRTHDATE" : "",
            "SALARY" : "",
            "BONUS" : "",
            "COMM" : "",
            "JZ_CURRENCY" : "",
            "Checksum" : ""
         }
      }
   }
}

OUTPUT
JSON:
{
   "JSPG2" : {
      "IJSPG2" : {
         "JZ_Function" : "E",
         "JZ_Employee_Skip" : 0,
         "JZ_Employee" : {
            "EMPNO" : "90",
            "FIRSTNME" : "",
            "MIDINIT" : "",
            "LASTNAME" : "",
            "WORKDEPT" : "",
            "PHONENO" : "",
            "HIREDATE" : "",
            "JOB" : "",
            "EDLEVEL" : "",
            "SEX" : "",
            "BIRTHDATE" : "",
            "SALARY" : "",
            "BONUS" : "",
            "COMM" : "",
            "JZ_CURRENCY" : "",
            "Checksum" : ""
         }
      }
   }
}
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
2,120
Location
Chesapeake, VA
Programming Experience
10+
I understood the broader context of what you are trying to do. What I was looking for was information about how to actually make a call to the web endpoint. But I think it was staring me in the face because I've now been primed to think REST-ful APIs when the word "web service" is used. I was mentally skipping over the fact that WSDL was mentioned a couple of times and about the claims of easy it is to test things using SOAPUI... Probably because I tend to think of SOAP as using XML rather than JSON.

Anyway, the way to call the web service is to generate a proxy for your SOAP web service by telling Visual Studio that you have a reference to a service. You enter the URL for your WSDL and Visual Studio will generate a proxy class for you where you would set the properties on a IJSPG2, call a method and get back an OJSPG2 object. You won't have to touch any JSON. They would all be C# objects. The proxy class takes care of encoding and decoding the data as specified by the WSDL, and making the appropriate HTTP POST.

If you wanted to skip the proxy class, then you will have to dig up how to make SOAP calls using raw HTTP. I've long flushed that memory because I felt that it was over complicated and there had to be simpler. Thankfully RESTful web services came along. In general would would have to happen to you format a message body with your intended JSON payload wrapped with a SOAP envelope and then do a HTTP POST. The response you get back will have the response also wrapped by a SOAP envelope. You would parse the SOAP envelope to get the payload out.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
2,120
Location
Chesapeake, VA
Programming Experience
10+
This may or may not be helpful:
 

RobertbNZ

Active member
Joined
Jun 26, 2020
Messages
34
Programming Experience
Beginner
Don't be confused by the reference to software product "SOAPUI", I'm not interested in SOAP calls. SOAPUI is a software product from Smartbear that is an excellent tool for testing web services, whether SOAP or REST. The product name reflects its origins from the days when SOAP was the only web service standard available. Now SOAPUI seems to emphasis REST services, this is certainly what I'm using it for, but its tooling works with both types. Similarly, in my software, a "Web Service" is a program that communicates through HTTP with another program, and currently the only difference between SOAP and REST is whether you check WSDL or JSON in the generation dialog. All my current development is for REST services which seem to be much more flexible than SOAP, and I've largely lost interest in SOAP services. I expect further MANASYS Jazz development to be for REST only, and SOAP will get left behind unless somebody pays for the development. I'll Google "Consuming a REST service using HttpClient and see where that leads me.

Any recommendations?
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
2,120
Location
Chesapeake, VA
Programming Experience
10+
For a REST API you have to know the exact URL to POST to. No special SOAP envelope needed. Just POST the JSON to the URL, and read the response JSON. Usually using a HTTPClient is easiest.

I tend to use PostMan for REST-ful API testing.
 

RobertbNZ

Active member
Joined
Jun 26, 2020
Messages
34
Programming Experience
Beginner
Looks good. Referring me to HTTPClient is the key, I'm reading through various pages about this, and I think that HTTPClient together with Newtonsoft.json give me the answers I need for now. Thank you Skydiver. I expect that this won't be my last question :)
 
Top Bottom