1. Kiat Chun
  2. PowerBuilder
  3. Monday, 7 January 2019 03:38 AM UTC

Hi team,

I'm using PowerBuilder 2017 R3, and completely new to WSDL/SOAP and RESTful webservice API stuff.. .I need some help, don't know where/how to start, or what approach to take for programming this in PB.

I'm given two API urls, and some temporary ticket/keys to test call from a local PB client, which I am expecting some return value. But I don't know how to code this in PB client.

I have tried using httpclient and json parser, but I can't seem to get any meaningful data.

How do I write the code for the two API below? Can you help ?

Any help is greatly appreciated. Thanks in advance.

 

API 1

https://uatapi.ezyparcels.com/ezy2ship/api.wsdl

API 2

https://api.starshipit.com/api/addressbook

 

For the first API above, I need to call a function called getavailableservicesResponse

getavailableservicesResponse (soap:body, use = encoded)

Temporary UAT ticket:

1S8Gz_m1PflDkiu25z2tsByL_g_q5_UE0XgeZDKJtuN9XWyu9UvI6P7dyunOWFo6wPTsjpjtogg_jmYGm6CleQ,,

And given some data spec & example:

Example: XML

 

For the second API url, I need to test a Request URL below, and expecting some return value:

Temporary demo key: 3bf41f8e5f1c4da5b991a33aef0d7ebc

Schema:

{
 
"addresses": [
    {
     
"id": 0,
     
"name": "string",
     
"company": "string",
     
"building": "string",
     
"street": "string",
     
"suburb": "string",
     
"post_code": "string",
     
"city": "string",
     
"state": "string",
     
"country": "string",
     
"code": "string",
     
"telephone": "string",
     
"email": "string"
    }
  ]
}

I'm provided with some example using C#:

using System;
using System.Net.Http.Headers;
using System.Text;
using System.Net.Http;
using System.Web;

namespace CSHttpClientSample
{
   
static class Program
    {
       
static void Main()
       
{
            MakeRequest();
            Console.WriteLine(
"Hit ENTER to exit...");
            Console.ReadLine();
        }
       
       
static async void MakeRequest()
       
{
           
var client = new HttpClient();
           
var queryString = HttpUtility.ParseQueryString(string.Empty);

           
// Request headers
            client.DefaultRequestHeaders.Add(
"StarShipIT-Api-Key", "");
            client.DefaultRequestHeaders.Add(
"Ocp-Apim-Subscription-Key", "{subscription key}");

           
var uri = "https://api.starshipit.com/api/addressbook?" + queryString;

           
var response = await client.GetAsync(uri);
        }
    }
}

 

Link to developer API site: https://developers.starshipit.com/docs/services

 

Who is viewing this page
Kiat Chun Accepted Answer Pending Moderation
  1. Tuesday, 22 January 2019 01:59 AM UTC
  2. PowerBuilder
  3. # 1

Hi, sorry for late reply, I was travelling. Tthanks so much for your advise. The API is working now.

I am able to receive response through the API.

HTTPClient http 
http = CREATE HTTPClient

http.SetRequestHeader ("Content-Type", "application/json")
http.SetRequestHeader ("Host", "api.starshipit.com")
http.SetRequestHeader ("StarShipIT-Api-Key", "abc123")
http.SetRequestHeader ("Ocp-Apim-Subscription-Key", "abc123")

li_return = http.SendRequest ('Get', 'https://api.starshipit.com/api/addressbook') 

ls_responseheaders = http.GetResponseHeaders ()

IF li_return = 1 and http.GetResponseStatusCode () = 200 THEN.... codes.

 

The JSON response I received:

ls_stringbody = '{"addresses":[{"id":2521795,"name":"John Smith","company":"Company Ltd","building":"Building Name","street":"Street Name","suburb":"Suburb Name","post_code":"1000","city":"City Name","state":"NSW","country":"Australia","code":"123","telephone":"012345678","email":"email@testemail.com"},{"id":2521796,"name":"Jane Smith","company":"Company Ltd","building":"Building Name","street":"Street Name","suburb":"Suburb Name","post_code":"2000","city":"City Name","state":"NSW","country":"Australia","code":"123","telephone":"987654321","email":"email@testemail.com"}]}'

 

My next question is how to parse the JSON data into a datawindow. I will post this question in a separate Q&A thread.

Thank you again.

Kiat

 

Comment
  1. Armeen Mazda @Appeon
  2. Tuesday, 22 January 2019 20:20 PM UTC
Thank you for separating out your questions in separate thread.
  1. Helpful
There are no comments made yet.
Kevin Ridley Accepted Answer Pending Moderation
  1. Monday, 7 January 2019 14:17 PM UTC
  2. PowerBuilder
  3. # 2

Hi Kiat,

 You have 2 very very different options here.  If you choose the WSDL option, you will need to do the following:

1) Create a project to consume the WSDL and generate the needed PB objects.  You do this by File/New (Project Tab) Web Service Proxy Wizard.  Select the checkbox for .NET engine, then follow the wizard, entering the url for the WSDL to consume.  Note: PB is not always able to consume complicated WSDL.  I usually create a separate PBL to hold all of the objects created from running the project.

2) Run the project

3) View the objects created.  There is usually a service object (can only be viewed using View Source - but this shows methods and signatures).  PB usually creates nvo's (value objects containing only attributes that you set before sending as arguments to the methods, and response objects populated by the service).

4) Code - there are many examples you can Google for writing the code, but here's the basics.  the wizard creates a Connection Object.  First you connect using the connection object, then call connection.CreateInstance with the service object to get a local reference to the remote service.  If that succeeds, you can call any method of the service object - serviceobj.myfunction(valueobject).  Don't forget to populate the valueobject(s) with the appropriate info for the service.  I recommend always wrapping your WSDL service calls in a try/catch and catching SOAPException.  Also recommend using Fiddler to help trace communication between your client and the web service.

 

REST is becoming the new standard for web services, and it's a little more reliable in terms of PB being able to process more complicated result sets.  Here's a good link provided by Bruce Armstrong to get you started with REST.  Again, depending on complexity of what is returned, you may be able to use the RESTClient object and have the results returned directly to a datawindow.  If not, you can use the HTTPClient or OAuthClient to make the request and parse the JSON returned manually.

https://community.appeon.com/index.php/articles-blogs/tutorials-articles/2-powerbuilder/181-powerbuilder-2017-r2-new-feature-rest

Comment
  1. Kevin Ridley
  2. Monday, 7 January 2019 20:45 PM UTC
I would also add, if you choose the WSDL option, you will need to deploy additional files as well as the .NET DLL that PB generates for the service. I'd recommend using the REST option if you can.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.