Sure, here is sample code:
The snippet below creates an object of the class InmediataWs to send a message to a web service and receive a response from it. SendRealTimeMessage() does the sending. Right after sending, it waits for a response that gets saved into property cResponse of the class.
...
oImWs := InmediataWs():InitRealTime()
IF oImWs == NIL ;RETURN NIL ;ENDIF
oImWs:isSilent := isSilent
oImWs:cMessage := MemoRead( cFileName )
oImWs:SendRealTimeMessage()
cRet := oImWs:cResponse
oImWs:End()
The class itself may send/receive files or send/receive realtime messages. In the code below I show the methods of interest to you (only sending and receiving messages on realtime):
CLASS InmediataWs
DATA aFiles AS ARRAY INIT {}
DATA aRoutedFiles AS ARRAY INIT {}
DATA aResponse AS ARRAY INIT {}
DATA aRespPages AS ARRAY INIT {}
DATA cUserName, cPassword
DATA cMessage, cResponse
DATA lShowProgress INIT .F.
DATA lShowConnected INIT .F.
DATA isSilent INIT .F.
DATA oHttp, oXml, oMeter
METHOD InitRealTime()
METHOD InitFileTransfer()
METHOD End()
METHOD SendFiles()
METHOD GetResponse()
METHOD GetRoutedFiles()
METHOD SendRealTimeMessage()
METHOD GetRealTimeMessage()
END CLASS
//---------------------------------------------------------------------------
METHOD InitRealTime( oMeter ) CLASS InmediataWs
LOCAL isLogHttpProgress := GetValFromRepository( "X12WebService", "LogProgress", "NO" ) $ "YES,.T., TRUE,Y"
LOCAL nTimeOut := VAL( GetValFromRepository( "X12WebService", "TimeOut", "30000", "Timeout in milliseconds" ) )
LOCAL cUserName:= GetValFromRepository( "X12WebService", "UserName", "UserName" )
LOCAL cPassword:= GetValFromRepository( "X12WebService", "Password", "Pass" )
LOCAL cUrl := GetValFromRepository( "X12WebService", "RealTime_Eligibility_Url", ;
'https://www.inmediata.com/webservices/editransfer/edirealtime.asmx' )
TRY
::oHttp := tIPClientHTTP():new( cUrl, isLogHttpProgress )
CATCH
MsgStop( "Missing SSL libs or no access to https was found.", "Check Installation" )
RETURN NIL
END
IF ::oHttp == NIL ;RETURN NIL ;ENDIF
::ohttp:cConnetion:='Keep-Alive' // set to keep alive
::ohttp:bChunked := .T.
::oHttp:nConnTimeOut := nTimeOut
::cUserName := cUserName
::cPassword := cPassword
::oMeter := oMeter
IF ::oMeter != NIL
::oMeter:nTotal := 100
::oMeter:Show()
::oHTTP:exGauge := { | nAt, nTotal, oSelf| ::oMeter:Set( ( Max( nAt, 0.00001 ) / Max( nTotal, 0.00001 ) ) * 100 ) }
ENDIF
IF ::oHttp:open()
::oHttp:hFields[ 'Content-Type'] := 'application/soap+xml; charset=utf-8'
RETURN SELF
ENDIF
RETURN NIL
//---------------------------------------------------------------------------
METHOD End() CLASS InmediataWs
IF ::oMeter != NIL ; ::oMeter:hide() ; ENDIF
IF ::oHttp != NIL
::oHttp:Close()
::oHttp := NIL
ENDIF
::oXml := NIL
hb_gcAll( .T. )
RETURN NIL
//---------------------------------------------------------------------------
METHOD SendRealTimeMessage() CLASS InmediataWs
LOCAL cPost
cPost := ;
'<?xml version="1.0" encoding="utf-8"?>'+;
'<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">'+;
' <soap12:Header>'+;
' <AuthenticationHeader xmlns="https://www.inmediata.com/ws/EdiRealTime/">'+;
' <Username>' + ::cUserName + '</Username>'+;
' <Password>' + ::cPassword + '</Password>'+;
' </AuthenticationHeader>'+;
' </soap12:Header>'+;
' <soap12:Body>'+;
' <SendRealTime xmlns="https://www.inmediata.com/ws/EdiRealTime/">'+;
' <X12Data>' + ::cMessage + '</X12Data>'+;
' </SendRealTime>'+;
' </soap12:Body>'+;
'</soap12:Envelope>'
IF ::oHttp:Post( cPost ) ;::GetRealTimeMessage() ;ENDIF
RETURN NIL
//---------------------------------------------------------------------------
METHOD GetRealTimeMessage() CLASS InmediataWs
LOCAL oXmlDoc := TXmlDocument():New()// HBXML_STYLE_NOESCAPE )
LOCAL cResponse
LOCAL oXmlNode, cRet
//::bChunked := .T.
//::nLength := 32000
cResponse := ::oHttp:ReadAll()
//logfile( "trace.log", { cResponse, ::bChunked, ::nConnTimeout, ::cConnetion } )
oXmlDoc:Read( cResponse )
oXmlNode := oXmlDoc:FindFirst( "RealTimeResponse" )
IF oXmlNode != NIL ;cRet := oXmlNode:cData ;ENDIF
oXmlNode := NIL
oXmlDoc := NIL
::cResponse := cRet
RETURN cRet
Hope that helps,
Reinaldo.