1. Libby Engelbret
  2. PowerBuilder
  3. Tuesday, 29 May 2018 21:25 PM

I am attempting to get xml from a website in my PB 2017 application, and use PBDOM to read it.  Everything works fine on my development box but when I deploy it to the client it doesn't work.  I deleted all of the pbdom files and reimported pbdom17.pbx.  Everything compiles fine.  When it didn't work, I tried deploying every dll, in case it was missing something.  Still no luck.  Here is the code.  I have obscured the appid and appkey in the url so they won't work.  That is not the problem in any case, because it is failing on the last statement (BuildFromString), which means  the website is returning 200 (the valid status code).  The error message it gives is "Bad runtime function reference at line 103...", which is the last line of the code I pasted in.  Can anyone help?  

lole_Send = CREATE OleObject

lole_SrvHTTP = CREATE OleObject

lole_Send.connectToNewObject("Msxml2.DOMDocument.6.0")
lole_SrvHTTP.connectToNewObject("MSXML2.ServerXMLHTTP.6.0")
IF ISNULL(p_szZip) OR p_szZip = "" THEN
szApiString =  "https://api.cityofnewyork.us/geoclient/v1/address.xml?houseNumber=" + szStreetNumber + "&street=" + szStreet + "&borough=" + szBoroughName +"&app_id=4fxxx&app_key=1xxxx"
ELSE
szApiString = "https://api.cityofnewyork.us/geoclient/v1/address.xml?houseNumber=" + szStreetNumber + "&street=" + szStreet + "&zip=" + p_szZip +"&app_id=4f4xxx&app_key=1xxxxx"
END IF
TRY
lole_SrvHTTP.Open("GET",szApiString, FALSE)
lole_SrvHTTP.SetRequestHeader( "Content-Type", "application/json")
lole_SrvHTTP.Send(lole_Send)
ls_status = string(lole_SrvHTTP.Status)
ls_response = string(lole_SrvHTTP.ResponseText)
 
CATCH (Runtimeerror er)
f_display_message('501|Unable to set electoral districts at this time. ')
END TRY
 
IF ls_status <> "200" THEN
RETURN '-1'
END IF
 
lReturn = XMLParseString(ls_response, ValNever!, szParsingErrors)
pbdom_bldr = Create PBDOM_Builder
pbdom_doc = pbdom_bldr.BuildFromString(ls_response)
Libby Engelbret Accepted Answer Pending Moderation
  1. Wednesday, 30 May 2018 16:18 PM
  2. PowerBuilder
  3. # 1
0
Votes
Undo

Thanks for the suggestions.  I tried a combination of both.  I moved my "TRY" up so that it encompassed the creation of the OleObject.  I figured it wasn't that, because it was returning a "200" status code from the site (which means it must have connected), but I checked the registry to be sure and it was registered.  Also, it's important to note that this was existing code and the machine it's running on at the client hasn't changed, only the version of PB.  I also added the two extra PBDOM errors, along with a general runtime error in case it wasn't one of the PBDOM errors.  The general runtime error is what fired, and it pointed to the same line (pbdom_doc = pbdom_bldr.BuildFromString(ls_response)).  Bad runtime function error again.  So, I'm at a loss once again as to what to try.  Any other suggestions would be greatly appreciated.  The new code is below.  Thanks!

TRY
lole_Send = CREATE OleObject
lole_SrvHTTP = CREATE OleObject
lole_Send.connectToNewObject("Msxml2.DOMDocument.6.0")
lole_SrvHTTP.connectToNewObject("MSXML2.ServerXMLHTTP.6.0")
IF ISNULL(p_szZip) OR p_szZip = "" THEN
szApiString =  "https://api.cityofnewyork.us/geoclient/v1/address.xml?houseNumber=" + szStreetNumber + "&street=" + szStreet + "&borough=" + szBoroughName +"&app_id=4fxxa&app_key=18xxx"
ELSE
szApiString = "https://api.cityofnewyork.us/geoclient/v1/address.xml?houseNumber=" + szStreetNumber + "&street=" + szStreet + "&zip=" + p_szZip +"&app_id=4fxx9a&app_key=1830xxxw"
END IF
 
lole_SrvHTTP.Open("GET",szApiString, FALSE)
lole_SrvHTTP.SetRequestHeader( "Content-Type", "application/json")
lole_SrvHTTP.Send(lole_Send)
ls_status = string(lole_SrvHTTP.Status)
ls_response = string(lole_SrvHTTP.ResponseText)
 
CATCH (Runtimeerror er)
f_display_message('501|Unable to set electoral districts at this time. ' + 'Error Message: ' + er.getMessage())
RETURN '-1'
END TRY
 
IF ls_status <> "200" THEN
RETURN '-1'
END IF
 
TRY
lReturn = XMLParseString(ls_response, ValNever!, szParsingErrors)
pbdom_bldr = Create PBDOM_Builder
pbdom_doc = pbdom_bldr.BuildFromString(ls_response)
 
//get the root element
szRootElementName = pbdom_doc.GetRootElement().GetName()
 
//the following displays the row, element and text
pbdom_doc.GetRootElement().GetContent(pbdom_obj_array)
 
FOR l = 1 to UpperBound(pbdom_obj_array)
pbdom_object1 = pbdom_obj_array[l]
pbdom_object1.GetContent(pbdom_elem_array)
FOR lIndex = 1 to UpperBound(pbdom_elem_array)
pbdom_elem = pbdom_elem_array[lIndex]
szName = UPPER(pbdom_elem.GetName())
szText = pbdom_elem.GetText()
 
CHOOSE CASE UPPER(szName)
CASE 'ASSEMBLYDISTRICT'
szAssemblyDist = szText
CASE 'CITYCOUNCILDISTRICT'
szCityCouncil = szText
CASE 'CONGRESSIONALDISTRICT'
szCongressDist = szText
CASE 'STATESENATORIALDISTRICT'
szSenatorialDist = szText
END CHOOSE
NEXT
NEXT
CATCH ( PBDOM_Exception pbde )
  f_display_message('501|PBDOM Exception' + pbde.getMessage() )
RETURN '-1'
CATCH ( PBXRuntimeError re )
   f_display_message('501|PBNI Exception' + pbde.getMessage() )
RETURN '-1'
CATCH (RuntimeError ex)
  f_display_message('501|Runtime Exception' + ex.getMessage() )
RETURN '-1'
END TRY
Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 30 May 2018 00:03 AM
  2. PowerBuilder
  3. # 2
0
Votes
Undo

Hi Libby;

       I suspect that your problem is not PBDOM object and code. My guess is that its an issue with your OLE Control`s objects "Msxml2.DOMDocument.6.0" or "MSXML2.ServerXMLHTTP.6.0" external controls. These controls may not be present on your target machine or may in fact not work the same on MS-Windows Server O/S`s vs W7/8/10.

     I also notice that you do not check the return codes on all your method calls. Especially for example, the ones around the connectToNewObject command.

HTH

Regards ... Chris

Comment
I posted a response, but I posted it as an answer instead of a reply, which is probably the wrong place.  Please take a look if you get a chance.

  1. Libby Engelbret
  2. Wednesday, 30 May 2018 16:19 PM
There are no comments made yet.
Govinda Lopez @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 29 May 2018 22:01 PM
  2. PowerBuilder
  3. # 3
0
Votes
Undo

Hi Libby,

 

Have you tried catching the PBDOM Exception? You could add the following lines:

CATCH ( PBDOM_Exception pbde )
   MessageBox( "PBDOM Exception", pbde.getMessage() )
CATCH ( PBXRuntimeError re )
   MessageBox( "PBNI Exception", re.getMessage() )
END TRY

After that you can check for the specific exception here.

 

 

Regards,

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.