1. Malek Taha
  2. PowerBuilder
  3. Wednesday, 21 April 2021 19:20 PM UTC

Hi

    I have an application written in Powerbuilder.Net converted to Powerbuilder 2019 R3. The app functions as expected until a function is called that sends an xml request to UPS and receiving a response back.

This is the code of the function that no longer works.

Can someone help in transforming this function to PB 2019 R3?

The parameters to the function are string asurl, value, string asrequest value and string asresponse Reference

 

Please respond

THanks

Malek Taha

 

Function talktoups

// this function uses the web post to communicate with UPS web services via XML documents
// the process issues a request by sending an XML document to a URL and receives back an XML document.

 


#if defined PBDOTNET then

try

GMaPSCommon.gasecurity.tls12()

@System.IO.StringWriter sWriter
@System.Net.HttpWebRequest myHttpWebRequest
@System.Net.WebRequest myWebRequest
@System.Net.WebResponse myWebResponse
@System.IO.Stream stream
@System.IO.StreamReader myReader
@System.IO.StreamWriter myWriter


myWebRequest = @System.Net.WebRequest.Create(asURL)
myHttpWebRequest = myWebRequest
myHttpWebRequest.Method = "POST"

myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"
myHttpWebRequest.ContentLength = len(asRequest)

//send request using stream writer
stream = myHttpWebRequest.GetRequestStream()
myWriter = Create @System.IO.StreamWriter(stream)
myWriter.Write(asRequest)
myWriter.Close()

//receive response using stream reader
myWebResponse = myHttpWebRequest.GetResponse()
stream = myWebResponse.GetResponseStream()
myReader = Create @System.IO.StreamReader(stream)
asResponse = myReader.ReadToEnd()


catch (@System.Exception e)
messagebox("Talk To UPS Error", e.Message)

end try

#end if

 

return 0

Daryl Foster Accepted Answer Pending Moderation
  1. Wednesday, 21 April 2021 23:56 PM UTC
  2. PowerBuilder
  3. # 1

Hi Malek,

 

As Armeen says, there might be a more modern API that UPS have which you can use.  In your example above it doesn't look like you send any authorisation credentials. 

The other unusual thing is that you are setting the Content-Type to application/x-www-form-urlencoded, but you say you are sending XML, so you may need a different content type header.  But if it currently works I think the below Powerscript should be a straight replacement for your code.  The only thing I'm not sure about is the call to GMaPSCommon.gasecurity.tls12(), do you know what that does?

// I don't know what the below line of code does, so it may affect the result
// GMaPSCommon.gasecurity.tls12()

integer li_response
string ls_responsebody
string ls_responsestatustext
integer li_rc

HttpClient lo_httpclient
lo_httpclient = Create HttpClient

lo_httpclient.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded')

li_rc = lo_httpclient.SendRequest('POST', asURL, asRequest)

if li_rc = 1 then
    // I normally check the Response Status Code to make sure it's what I am expecting
    li_response = lo_httpclient.GetResponseStatusCode()
    ls_responsestatustext = lo_httpclient.GetResponseStatusText()
    
    li_rc = lo_httpclient.GetResponseBody(asresponse)
    if li_rc <> 1 then
        MessageBox('Talk To UPS Error', 'Error reading response from ' + asURL + '~r~nReturn Code ' + string(li_rc))
    end if
else
    MessageBox('Talk To UPS Error', 'Error calling ' + asURL + '~r~nReturn Code ' + string(li_rc))
end if
destroy lo_httpclient

 

Comment
There are no comments made yet.
Armeen Mazda @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 21 April 2021 19:37 PM UTC
  2. PowerBuilder
  3. # 2

PBDOTNET compiler directive is obsolete. You need to rewrite this in PowerScript and use the HTTPClient object.  https://docs.appeon.com/pb2019r3/objects_and_controls/ch02s41.html

You mentioned this is a UPS Web service you are calling.  I'm guessing they must have a modern modern API that is REST/JSON.  If they do, then you can used the specialized RESTClient object to call REST APIs.  https://docs.appeon.com/pb2019r3/objects_and_controls/ch02s87.html

FYI, PowerBuilder now supports tokens, such as OAuth and JWT that many modern Web services require to authenticate.

Comment
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.