1. DIPANJAN DUTTA
  2. PowerBuilder
  3. Wednesday, 8 May 2019 03:15 AM UTC

Hi Expert,

 

I am using PowerBuilder 12.5 Classic need to consume a RESTFUL service.

If anybody have the same experiences, then please guide me.

Is it possible to use of MSXML OLE object? If yes how to do it?

I would highly appreciate all your advice on this issue.

 

Regards,

Dipanjan

Accepted Answer
DIPANJAN DUTTA Accepted Answer Pending Moderation
  1. Wednesday, 8 May 2019 16:40 PM UTC
  2. PowerBuilder
  3. # Permalink

HI René

Finally, I have implemented consumption of RESTFul service...........with your help of your sample example.....

Here is my Code

OLEObject lole_SrvHTTP
Long li_ret, li_number, ll_resultstatus
string ls_word, ls_url, ls_responseheaders

If IsNumber(em_number.Text) Then
li_number = Long(em_number.Text)
Else
Return
End If

ls_url = "http://www.dataaccess.com/webservicesserver/numberconversion.wso/NumberToWords/JSON/debug?ubiNum=" + &
Trim(em_number.Text)

Try

lole_SrvHTTP = Create OLEObject
li_ret = lole_SrvHTTP.ConnectToNewObject("Msxml2.XMLHTTP.4.0")

lole_SrvHTTP.OPEN ("GET" , ls_url,FALSE)
lole_SrvHTTP.Send()

ll_resultstatus = lole_SrvHTTP.status
If ll_resultstatus = 200 Then
st_inword.Text = String (lole_SrvHTTP.ResponseText)
End If

Catch (Exception e)
st_inword.Text = e.Text
End Try

lole_SrvHTTP.DisconnectObject ()
Destroy(lole_SrvHTTP)

 

Comment
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Wednesday, 8 May 2019 05:37 AM UTC
  2. PowerBuilder
  3. # 1

Hi,

Yes, you can use MSXML OLE object. You can use Msxml2.XMLHTTP or Msxml2.ServerXMLHTTP. Which one is better for you depends on your requirements. If you use REST with XML and GET you may also directly use Msxml2.DOMDocument or Msxml2.FreeThreadedDOMDocument and its Load method.

 

Here a simple example to start:

TRY
    lole_XmlHttp = create oleobject
    lole_XmlHttp.ConnectToNewObject ("Msxml2.XMLHTTP")

    // call REST API (here GET method)
    lole_XmlHttp.Open ("GET", as_url, FALSE)
    lole_XmlHttp.Send ()

    // get the result
    as_result = string (lole_XmlHttp.ResponseText)
    as_responseheaders = String (lole_XmlHttp.getAllResponseHeaders())
    al_resultstatus = lole_XmlHttp.status

CATCH (OLERuntimeError errole)
    // Catch OLE runtime errors here (e.g. Timeout)
    
CATCH (Throwable e)
    // Catch other errors here
    
FINALLY
    IF IsValid (lole_XmlHttp) THEN lole_XmlHttp.DisconnectObject ()
    DESTROY lole_XmlHttp
END TRY

 

HTH,

René

 

 

Comment
  1. DIPANJAN DUTTA
  2. Wednesday, 8 May 2019 06:07 AM UTC
Thanks......René........I will try this.........Basically I have to use POST methods........and receive output in JSON format
  1. Helpful
  1. René Ullrich
  2. Wednesday, 8 May 2019 06:10 AM UTC
My example should work for you. Simply change "GET" to "POST" for open method.
  1. Helpful
  1. DIPANJAN DUTTA
  2. Wednesday, 8 May 2019 16:35 PM UTC
Hi René.......Thanks a lots..........Your Code is working fine .......I have successfully implemented this using your approach.
  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.