Page 1 of 1

Where do I start the Web Service?

Posted: Wed Jul 20, 2022 9:43 am
by dutch
Dear All,

I must communicate with website. I think the web service is way to do.
Where do I start?

I try but not successful. It show error
Application
===========
Path and name: d:\FWH1901\samples\testws.exe (32 bits)
Size: 3,732,480 bytes
Compiler version: xHarbour 1.2.3 Intl. (SimpLex) (Build 20180609)
FiveWin version: FWH 18.10
C compiler version: Borland/Embarcadero C++ 7.3 (32-bit)
Windows version: 6.2, Build 9200

Time from start: 0 hours 0 mins 0 secs
Error occurred at: 07/20/22, 16:42:18
Error description: Error MSXML2.XMLHTTP/3 DISP_E_MEMBERNOTFOUND: SEND
Args:
[ 1] = C

Code: Select all | Expand

#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   local odoc  := CreateObject( "MSXML2.DOMDocument" )
   local ohttp := CreateObject( "MSXML2.XMLHTTP" )
   local strret

   ohttp:Open( "GET" ,"http://www.w3schools.com/angular/customers.php", .F. )
   ohttp:SetRequestHeader( "Accept"        , "application/xml")
   ohttp:SetRequestHeader( "Content-Type" ,"application/json" )
   oDoc:async := .f.
   oDoc:LoadXml('<?xml version=""1.0"" encoding=""utf-8""?>')
   ohttp:Send(oDoc:xml)
   strret := alltrim(ohttp:responseText)

   ? StrRet

//   StrToHashArray( StrRet )
   SaveToDBF( StrRet )

return nil

function SaveToDBF( cStr )

   local hData

   cStr  := CharRepl( "[]", RangeRem( 1, 31, cStr ), "{}" )
   do while '" :' $ cStr
      StrTran( cStr, '" :', '":' )
   enddo
   cStr  := StrTran( cStr, '":', '"=>' )

   hData := &cStr

   if File( "download.dbf" )
      USE download.dbf NEW ALIAS DST EXCLUSIVE VIA "DBFCDX"
   else
      DBCREATE( "download.dbf", { { "NAME",    'C', 40, 0 }, ;
                                  { "CITY",    'C', 40, 0 }, ;
                                  { "COUNTRY", 'C', 40, 0 } }, ;
                "DBFCDX", .t., "DST" )
   endif

   AEval( HGetValueAt( hData, 1 ), { |h| DBAPPEND(), FW_HashToRec( h ) } )

   XBROWSER

   CLOSE DST

return nil



Thank in advance for any idea.

Re: Where do I start the Web Service?

Posted: Wed Jul 20, 2022 12:41 pm
by leandro
Creo que debes hacerlo así

Code: Select all | Expand


#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   local odoc  := CreateObject( "MSXML2.DOMDocument" )
   local ohttp := CreateObject( "MSXML2.XMLHTTP" )
   local strret
   local hRespn  := hash()

   ohttp:Open( "GET" ,"http://www.w3schools.com/angular/customers.php", .F. )
   ohttp:SetRequestHeader( "Accept"        , "application/xml")
   ohttp:SetRequestHeader( "Content-Type" ,"application/json" )
   oDoc:async := .f.
   oDoc:LoadXml('<?xml version=""1.0"" encoding=""utf-8""?>')
   ohttp:Send(oDoc:xml)
   strret := alltrim(ohttp:responseText)
   
   hb_jsondecode(strret,@hRespn ) //Parse JSON to hash*/
   xbrowse(hRespn)


   ? StrRet

//   StrToHashArray( StrRet )
   SaveToDBF( StrRet )

return nil
 

Re: Where do I start the Web Service?

Posted: Wed Jul 20, 2022 1:11 pm
by dutch
Dear leandro,

I've got the same error. I don't know which library I miss. ::Sebd() method is unknow.
Application
===========
Path and name: d:\FWH1901\samples\testws.exe (32 bits)
Size: 3,731,968 bytes
Compiler version: xHarbour 1.2.3 Intl. (SimpLex) (Build 20180609)
FiveWin version: FWH 18.10
C compiler version: Borland/Embarcadero C++ 7.3 (32-bit)
Windows version: 6.2, Build 9200

Time from start: 0 hours 0 mins 0 secs
Error occurred at: 07/20/22, 20:09:25
Error description: Error MSXML2.XMLHTTP/3 DISP_E_MEMBERNOTFOUND: SEND
Args:
[ 1] = C

Stack Calls
===========
Called from: => TOLEAUTO:SEND( 0 )
Called from: testws.prg => MAIN( 17 )

leandro wrote:Creo que debes hacerlo así

Code: Select all | Expand


#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   local odoc  := CreateObject( "MSXML2.DOMDocument" )
   local ohttp := CreateObject( "MSXML2.XMLHTTP" )
   local strret
   local hRespn  := hash()

   ohttp:Open( "GET" ,"http://www.w3schools.com/angular/customers.php", .F. )
   ohttp:SetRequestHeader( "Accept"        , "application/xml")
   ohttp:SetRequestHeader( "Content-Type" ,"application/json" )
   oDoc:async := .f.
   oDoc:LoadXml('<?xml version=""1.0"" encoding=""utf-8""?>')
   ohttp:Send(oDoc:xml)
   strret := alltrim(ohttp:responseText)
   
   hb_jsondecode(strret,@hRespn ) //Parse JSON to hash*/
   xbrowse(hRespn)


   ? StrRet

//   StrToHashArray( StrRet )
   SaveToDBF( StrRet )

return nil
 

Re: Where do I start the Web Service?

Posted: Wed Jul 20, 2022 2:06 pm
by cmsoft
Acá me trae la respuesta pero el no me lo decodifica bien el hb_jsondecode, porque esta dentro del valor de respuesta

Code: Select all | Expand


#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   local odoc  := CreateObject( "MSXML2.DOMDocument" )
   local ohttp := Createobject("MSXML2.ServerXMLHTTP")
   local strret
   local hRespn  := hash(), hRespn1 := hash()

   ohttp:Open( "GET" ,"http://www.w3schools.com/angular/customers.php", .F. )
   ohttp:SetRequestHeader( "Accept"        , "application/xml")
   ohttp:SetRequestHeader( "Content-Type" ,"application/json" )
   oDoc:async := .f.
   oDoc:LoadXml('<?xml version=""1.0"" encoding=""utf-8""?>')
   ohttp:Send(oDoc:xml)
   
   strret := alltrim(ohttp:responseText)
   
   hb_jsondecode(strret,@hRespn ) //Parse JSON to hash*/

   xbrowse(hRespn1)


   //? StrRet

//   StrToHashArray( StrRet )
   //SaveToDBF( StrRet )

return nil

Re: Where do I start the Web Service?

Posted: Wed Jul 20, 2022 2:12 pm
by cmsoft
Corrijo
Asi te lo trae

Code: Select all | Expand

#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   local odoc  := CreateObject( "MSXML2.DOMDocument" )
   local ohttp := Createobject("MSXML2.ServerXMLHTTP")
   local strret
   local hRespn  := hash(), hRespn1 := hash()

   ohttp:Open( "GET" ,"http://www.w3schools.com/angular/customers.php", .F. )
   ohttp:SetRequestHeader( "Accept"        , "application/xml")
   ohttp:SetRequestHeader( "Content-Type" ,"application/json" )
   oDoc:async := .f.
   oDoc:LoadXml('<?xml version=""1.0"" encoding=""utf-8""?>')
   ohttp:Send(oDoc:xml)
   
   strret := alltrim(ohttp:responseText)
   
   hb_jsondecode(strret,@hRespn ) //Parse JSON to hash*/
   //hb_jsondecode(hRespn["records"],@hRespn1 )

   xbrowse(hRespn["records"])


   //? StrRet

//   StrToHashArray( StrRet )
   //SaveToDBF( StrRet )

return nil

Image

Re: Where do I start the Web Service?

Posted: Wed Jul 20, 2022 5:10 pm
by Antonio Linares
Querido César,

muchas gracias !

Re: Where do I start the Web Service?

Posted: Thu Jul 21, 2022 2:21 am
by dutch
Dear cmsoft,

Thank you, it works now.

This is the way to get from web server. How can I do the web server to response from web application? The web app will send request and I must reply data back.

cmsoft wrote:Corrijo
Asi te lo trae

Code: Select all | Expand

#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   local odoc  := CreateObject( "MSXML2.DOMDocument" )
   local ohttp := Createobject("MSXML2.ServerXMLHTTP")
   local strret
   local hRespn  := hash(), hRespn1 := hash()

   ohttp:Open( "GET" ,"http://www.w3schools.com/angular/customers.php", .F. )
   ohttp:SetRequestHeader( "Accept"        , "application/xml")
   ohttp:SetRequestHeader( "Content-Type" ,"application/json" )
   oDoc:async := .f.
   oDoc:LoadXml('<?xml version=""1.0"" encoding=""utf-8""?>')
   ohttp:Send(oDoc:xml)
   
   strret := alltrim(ohttp:responseText)
   
   hb_jsondecode(strret,@hRespn ) //Parse JSON to hash*/
   //hb_jsondecode(hRespn["records"],@hRespn1 )

   xbrowse(hRespn["records"])


   //? StrRet

//   StrToHashArray( StrRet )
   //SaveToDBF( StrRet )

return nil

Image