Using WebServices in PowerBuilder

Home Forums Discussion Board Using WebServices in PowerBuilder

This topic contains 2 replies, has 2 voices, and was last updated by  pbgeeks 6 months ago.

  • Author
    Posts
  • #71

    pbgeeks
    Keymaster

    Has anyone consumed Web Services in your Power Builder Application? Can you let me know how you have achieved the same. Thanks.

  • #75

    satish
    Participant

    Thanks

    • #100

      pbgeeks
      Keymaster

      You can call REST Services using two different methods. One is to use the iNET object and the other is to use MSXML.

      MSXML:

      loo_xmlhttp = CREATE oleobject

      // make a connection to Msxml2.XMLHTTP.4.0

      loo_xmlhttp.ConnectToNewObject(“Msxml2.XMLHTTP.6.0”)

      // invoke POST method for REST web service

      loo_xmlhttp.open (astr_rs.in_method_type, is_url_send, false)

      // building HTTP request headers

      lblb_args = blob(astr_rs.in_arg_data)

      ll_length = Len(lblb_args)

      loo_xmlhttp.setRequestHeader(“Content-Type”, is_headers_content_type)

      loo_xmlhttp.setRequestHeader(“Content-Length”, String( ll_length ))

      loo_xmlhttp.setRequestHeader(“Authorization”, is_headers_authorization)

      loo_xmlhttp.setRequestHeader(“If-Modified-Since”, string(today()))

      loo_xmlhttp.setRequestHeader(“Accept”, ‘text/xml’)

      // send request XML

      loo_xmlhttp.send(astr_rs.in_arg_data)

      iNET Object:

      data = CREATE n_cst_internet
      lblb_args = blob(astr_rs.in_arg_data,EncodingAnsi!)
      ll_length = Len(lblb_args)

      ls_headers = “Content-Type: “+ is_headers_content_type + “~n” &

      + “Content-Length: ” + string(ll_length) + “~n” &

      + “Authorization: ” + is_headers_authorization + “~n” &

      + “If-Modified-Since: ” + string(today()) + “~n” &

      + “Accept: text/xml” + “~n~n”

      li_rc = GetContextService( “Internet”, iinet_base )

      IF li_rc = 1 THEN

      ll_status_code= iinet_base.PostURL (is_url_send, lblb_args, ls_headers, data)
      IF ll_status_code = -1 Then
      ls_status_text = “There was an Error accessing Rest Service – General error”
      ElseIf ll_status_code = -2 Then
      ls_status_text = “There was an Error accessing Rest Service – Invalid URL”
      ElseIf ll_status_code = -4 Then
      ls_status_text = “There was an Error accessing Rest Service – Cannot connect to the Internet”
      ElseIf ll_status_code = -5 Then
      ls_status_text = “There was an Error accessing Rest Service – Unsupported secure (HTTPS) connection attempted”
      ElseIf ll_status_code = -6 Then
      ls_status_text = “There was an Error accessing Rest Service – Internet request failed”
      End IF
      End If

      // response from the service

      ls_status_text = ls_status_text

      ll_status_code = ll_status_code

      ls_response_text = String(data.iblog_data,EncodingAnsi!)

      If isvalid(iinet_base) Then Destroy iinet_base

      If isvalid(data) Then Destroy data

You must be logged in to reply to this topic.