Communication via HTTP with SOAP

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

edk
Posts: 911
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Communication via HTTP with SOAP

Post by edk »

Hi Steed.
Based on the WSDL schema, I prepared a SOAP query.
Unfortunately, I get information that the connection is being refused.
Log from SoapUI:

Code: Select all

Error getting response for [TCRMServicesWebServiceSoapBinding.queryTCRM:Request 1]; org.apache.http.conn.HttpHostConnectException: Connection to http://superfinanciera.gov.co:8080 refused
This may be related to, for example, blocking requests from domains other than .co or authorization is required.
No additional hints in the WSDL scheme.
Do you have any documentation for this WEB Service in English?
Attachments
Steed.7z
(4.24 KiB) Downloaded 185 times
User avatar
Steed
Posts: 427
Joined: Sat Dec 12, 2009 3:40 pm

Re: Communication via HTTP with SOAP

Post by Steed »

Thanks a lot, Edk

It looks to work fine, changing line 121 (taking off the :8080)

Local TCRMUrl := "http://superfinanciera.gov.co:8080/SuperfinancieraWebServiceTRM/TCRMServicesWebService/TCRMServicesWebService"

by

Local TCRMUrl := "http://superfinanciera.gov.co/SuperfinancieraWebServiceTRM/TCRMServicesWebService/TCRMServicesWebService"

Captura.JPG
Captura.JPG (32.92 KiB) Viewed 3202 times

But how to save only the data highlighted in Yellow ?,


Thanks again,

ES
edk
Posts: 911
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Communication via HTTP with SOAP

Post by edk »

Steed
Indeed. :!: :o
I don't understand why in the definition wsdl say: :?:

Code: Select all

 <soap: address location = "http://superfinanciera.gov.co:8080/SuperfinancieraWebServiceTRM/TCRMServicesWebService/TCRMServicesWebService" />
Very strange. X :?
Last edited by edk on Tue Jul 24, 2018 10:28 pm, edited 1 time in total.
edk
Posts: 911
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Communication via HTTP with SOAP

Post by edk »

Steed wrote: Tue Jul 24, 2018 9:01 pm But how to save only the data highlighted in Yellow ?,
Thanks again,

ES
Eduar, try this:

Code: Select all

#include "hmg.ch"

Function Main()
SET CENTURY ON
SET LANGUAGE TO SPANISH
SET NAVIGATION EXTENDED

DEFINE WINDOW TCRMForm AT 0 , 0 WIDTH 270 HEIGHT 200 TITLE 'TCRMServicesWebService' MAIN;
	NOMINIMIZE; 
	NOMAXIMIZE; 
	NOSIZE

	DEFINE LABEL Label_1
		ROW    30
		COL    40
		WIDTH  120
		HEIGHT 20
		VALUE "Associated Date"
		ALIGNMENT Right
	END LABEL

	DEFINE DATEPICKER dDate
		ROW    55
		COL    70
		WIDTH  120
		HEIGHT 24
		VALUE DATE()
	END DATEPICKER
	
	DEFINE BUTTON Button_1
		ROW    100
		COL    80
		WIDTH  100
		HEIGHT 28
		ACTION TCRMApi(TCRMForm.dDate.Value)
		CAPTION "Query"
	END BUTTON
	
	DEFINE STATUSBAR FONT "MS Shell Dlg" SIZE 7
		STATUSITEM HMGVersion()
		CLOCK
	END STATUSBAR
	
	ON KEY ESCAPE ACTION ThisWindow.Release

END WINDOW

CENTER WINDOW TCRMForm
ACTIVATE WINDOW TCRMForm


Return Nil

****************************************************************************************
Function TCRMApi( dDate )
Local RespHttp, oHttp, SOAP_Form, cResp

TCRMForm.Button_1.Enabled := .F.

IF !isInternet()
	MsgExclamation("No Internet connection.", "Warning")
	TCRMForm.Button_1.Enabled := .T.
	RETURN 
ENDIF

info_('Initializing...')

//Init 
oHttp := TCRM_api_init()
IF EMPTY(oHttp)
	Info_("Error while initialization MSXML",.T.)
	WAIT CLEAR
	TCRMForm.Button_1.Enabled := .T.
ENDIF

info_('Quering...')

SOAP_Form := '<tcrmQueryAssociatedDate>' + SOAPDate( dDate ) + '</tcrmQueryAssociatedDate>'

RespHttp := TCRM_api_Execute( oHttp , Envelope( SOAP_Form ) )

IF EMPTY(RespHttp)
	info_('No data',.T.)
	WAIT CLEAR
ELSE
	WAIT CLEAR
	cResp := 'id: ' + GetFromXml ( 'id', RespHttp ) + CRLF
	cResp += 'unit: ' + GetFromXml ( 'unit', RespHttp ) + CRLF
	cResp += 'validityFrom: ' + GetFromXml ( 'validityFrom', RespHttp ) + CRLF
	cResp += 'validityTo: ' + GetFromXml ( 'validityTo', RespHttp ) + CRLF
	cResp += 'value: ' + GetFromXml ( 'value', RespHttp ) + CRLF
	cResp += 'success: ' + GetFromXml ( 'success', RespHttp ) 
	MsgInfo( cResp, 'Response' )
ENDIF

TCRM_api_close( oHttp )

TCRMForm.Button_1.Enabled := .T.
RETURN

*****************************************************************************************
Function SOAPDate( dDate )
RETURN NTOC(YEAR(dDate),10,4,'0') + '-' + NTOC(MONTH(dDate),10,2,'0') + '-' + NTOC(DAY(dDate),10,2,'0')

*****************************************************************************************
Function TCRM_api_init()
Local oHttp := ""
BEGIN SEQUENCE WITH {|o| break(o)}
	oHttp := Win_OleCreateObject( "MSXML2.ServerXMLHTTP" )

RECOVER USING oErr
    	MsgStop(hb_StrToUTF8(oErr:Description) ,"Error Microsoft XML Core Services (MSXML)" )
     oHttp := ""
END SEQUENCE

RETURN oHttp
******************************************************************************************
Function TCRM_api_close( oHttp )
IF !EMPTY(oHttp)
	oHttp:Abort()
ENDIF
RETURN

******************************************************************************************
Function TCRM_api_Execute( oHttp , cXml )
Local TCRM_recv := ""
//Local TCRMUrl := "http://superfinanciera.gov.co:8080/SuperfinancieraWebServiceTRM/TCRMServicesWebService/TCRMServicesWebService"
Local TCRMUrl := "http://superfinanciera.gov.co/SuperfinancieraWebServiceTRM/TCRMServicesWebService/TCRMServicesWebService"

IF !EMPTY( oHttp )
	
	BEGIN SEQUENCE WITH {|o| break(o)}
		ohttp:Open( "POST", TCRMUrl, .F. )
		ohttp:setRequestHeader("Accept-Encoding", "gzip,deflate")
		ohttp:setRequestHeader("Content-Type", "text/xml;charset=UTF-8")
		ohttp:Send( cXml )
		TCRM_recv := ohttp:ResponseBody()
	
	RECOVER USING oErr
		TCRM_recv := ""
	    	MsgStop(hb_StrToUTF8(oErr:Description) , "Error" )
 
	END SEQUENCE
 	
ENDIF
RETURN TCRM_recv

************************************************
Function Envelope( cParameter )
Local cXml     := '' 
Local cUrlTCRM := "http://action.trm.services.generic.action.superfinanciera.nexura.sc.com.co/"
Local sEnvelO  := '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:act="' + cUrlTCRM + '">' + CRLF
Local sHeadO   := '<soapenv:Header>' + CRLF
Local sHeadC   := '</soapenv:Header>' + CRLF
Local sBodyO   := '<soapenv:Body>' + CRLF
Local sBodyC   := '</soapenv:Body>' + CRLF
Local sQueryO  := '<act:queryTCRM>' + CRLF
Local sQueryC  := '</act:queryTCRM>' + CRLF
Local sEnvelC  := '</soapenv:Envelope>' + CRLF

cXml := sEnvelO
cXml += sHeadO
cXml += sHeadC
cXml += sBodyO
cXml += sQueryO
cXml += cParameter+CRLF
cXml += sQueryC
cXml += sBodyC
cXml += sEnvelC

//msgbox(cXml, 'SOAP Envelope')

RETURN cXml

*****************************************
Function info_(cMessage, lWait)
Local nTimeIni := hb_MilliSeconds()
Default lWait := .F.
 
Wait Window cMessage NoWait
IF lWait
	WHILE( ( hb_MilliSeconds() - nTimeIni ) < 3 * 1000 )
		DO EVENTS
		hb_releaseCPU()
	ENDDO
ENDIF
RETURN Nil

*********************************
FUNCTION isInternet( nTimeOut )
Local aAddr:=hb_socketResolveINetAddr( "www.google.com" , 80 )
Local socket:=hb_socketOpen()
Local lIsNet
Default nTimeOut := 2000
lIsNet := !EMPTY( aAddr ) .AND. hb_socketConnect( socket , aAddr, nTimeOut )
hb_socketClose( socket )
RETURN lIsNet
*********************************
FUNCTION GetFromXml ( cTag, cXml )
Local cTagOpen :="<" + cTag + ">"
Local cTagClose := "</" + cTag + ">"
Local nPosTagOpen := AT ( cTagOpen, cXml )
Local nPosTagClose := AT ( cTagClose, cXml )
Local xValue := ""
IF nPosTagOpen > 0 .AND. nPosTagOpen < nPosTagClose
	xValue := SUBSTR( cXml, nPosTagOpen + LEN( cTagOpen ), nPosTagClose - ( nPosTagOpen + LEN( cTagOpen ) ) )
ENDIF
RETURN xValue
Edward.
User avatar
Steed
Posts: 427
Joined: Sat Dec 12, 2009 3:40 pm

Re: Communication via HTTP with SOAP

Post by Steed »

Thanks a lot again Edk, It works like a charm
Captura2.JPG
Captura2.JPG (15.98 KiB) Viewed 3183 times
User avatar
nekbmm
Posts: 118
Joined: Sat Jul 16, 2016 3:16 am
DBs Used: DBF,SQLite
Location: Ivanjica, Serbia

Re: Communication via HTTP with SOAP

Post by nekbmm »

Hi, i need some help with SOAP also

https://webservices.nbs.rs/Communicatio ... .asmx?WSDL

How do i forward AuthenticationHeader for this service?

nekbmm
edk
Posts: 911
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Communication via HTTP with SOAP

Post by edk »

Hi.

For example: GetCurrentExchangeRate request, SOAP Envelope should be:

Code: Select all

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:com="http://communicationoffice.nbs.rs">
   <soapenv:Header>
      <com:AuthenticationHeader>
         <!--Optional:-->
         <com:UserName>?</com:UserName>
         <!--Optional:-->
         <com:Password>?</com:Password>
         <com:LicenceID>?</com:LicenceID>
      </com:AuthenticationHeader>
   </soapenv:Header>
   <soapenv:Body>
      <com:GetCurrentExchangeRate>
         <com:exchangeRateListTypeID>?</com:exchangeRateListTypeID>
      </com:GetCurrentExchangeRate>
   </soapenv:Body>
</soapenv:Envelope>
"LicenceID" and "exchangeRateListTypeID" is required.
POST should be sent to: https://webservices.nbs.rs/Communicatio ... rvice.asmx
POST Headers:

Code: Select all

Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "http://communicationoffice.nbs.rs/GetCurrentExchangeRate"
Host: webservices.nbs.rs
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
For example: GetServiceVersion request, SOAP Envelope should be:

Code: Select all

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:com="http://communicationoffice.nbs.rs">
   <soapenv:Header>
      <com:AuthenticationHeader>
         <!--Optional:-->
         <com:UserName>?</com:UserName>
         <!--Optional:-->
         <com:Password>?</com:Password>
         <com:LicenceID>?</com:LicenceID>
      </com:AuthenticationHeader>
   </soapenv:Header>
   <soapenv:Body>
      <com:GetServiceVersion/>
   </soapenv:Body>
</soapenv:Envelope>
"LicenceID" is required.
POST should be sent to: https://webservices.nbs.rs/Communicatio ... rvice.asmx
POST Headers:

Code: Select all

Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "http://communicationoffice.nbs.rs/GetServiceVersion"
Host: webservices.nbs.rs
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Pay attention to SOAPAction. It is based on which request you want to use.

You handle the other requests similarly.
User avatar
nekbmm
Posts: 118
Joined: Sat Jul 16, 2016 3:16 am
DBs Used: DBF,SQLite
Location: Ivanjica, Serbia

Re: Communication via HTTP with SOAP

Post by nekbmm »

Thanks EDK i'll try it.
User avatar
nekbmm
Posts: 118
Joined: Sat Jul 16, 2016 3:16 am
DBs Used: DBF,SQLite
Location: Ivanjica, Serbia

Re: Communication via HTTP with SOAP

Post by nekbmm »

EDK,
Web service works fine now. However this part wasn't optional for our web service.
<!--Optional:-->
<com:UserName>?</com:UserName>
<!--Optional:-->
<com:Password>?</com:Password>
Br
edk
Posts: 911
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Communication via HTTP with SOAP

Post by edk »

The wsdl say: "minoccurs = 0", which means that the parameter does not have to occur, which is why SoapUI reports it as optional.

It's nice that it works properly.
Post Reply