FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Sending and Receiving XML Data
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
Sending and Receiving XML Data
Posted: Tue Feb 12, 2013 07:23 PM

Hello,

I have checked FWH support forum and see several topics but no clear solution to handle XML sending and receiving. Can someone provide sample code that will allow me to perform the following?

  1. XML Sending - I need to transmit XML data to a host and receive response from host

  2. XML Receiving - I need to receive XML data from a remote computer and provide an XML response back to remote computer

Many thanks in advance for your assistance.

Sincerely,

*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: Sending and Receiving XML Data
Posted: Tue Feb 12, 2013 08:23 PM
This is working for me.
Best regards,
Otto

Code (fw): Select all Collapse
#include "fivewin.ch" 
#include "fileio.ch"
#include "hbxml.ch"
#INCLUDE "FILEIO.CH"
*----------------------------------------------------------
Function Main()
 
   local loHyperlink := TOLEAuto():New( "Microsoft.XmlHttp" ) 
   local cXML
   local cURL

   cXML := memoread("teste.xml")
   
   cURL := "http://" 
   
   loHyperlink:Open( "POST", cURL, .f. ) 
   
   loHyperlink:setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
         
   cxml := "xmlstring=" + cxml
   
   loHyperlink:Send( cXML )
    
    if (At( "SUCCESS", upper(loHyperlink:responseText )) < 5)
        msginfo("responseText" + CRLF + loHyperlink:responseText)
        f_protokoll(loHyperlink:responseText)
    else
        msginfo("Senden war erfolgreich")
        f_protokoll("Senden war erfolgreich")
    endif
    
    

return nil 
//----------------------------------------------------------------------------//

function f_protokoll(cProtokoll)
   
  //...
RETURN NIL
//----------------------------------------------------------------------------//
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
Re: Sending and Receiving XML Data
Posted: Tue Feb 12, 2013 08:26 PM

Thank you Otto!

*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
Re: Sending and Receiving XML Data
Posted: Tue Feb 12, 2013 08:46 PM

Hi Otto,

I am receiving the following error message.

Error Microsoft.XmlHttp/3 DISP_E_MEMBERNOTFOUND: SEND

What am I doing wrong?

*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
Re: Sending and Receiving XML Data
Posted: Tue Feb 12, 2013 09:40 PM

Hi Otto,

Sorry, I was able to trap error and found that issue was with host computer.

By any chance do you have any sample code on receiving XML message and returning a response XML?

Thanks again for your help!

*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: Sending and Receiving XML Data
Posted: Tue Feb 12, 2013 10:54 PM
What is the response you get.

Code (fw): Select all Collapse
loHyperlink:responseText
Best regards,
Otto
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
Re: Sending and Receiving XML Data
Posted: Thu Feb 14, 2013 04:49 PM

Hello,

I was able to transmit the XML to the host server, however I am receiving the following error back from host server. Upon discussing with host server company, they are indicating the XML transmission is corrupt even though the XML message is well-formed and validated against a third party XML validation tool.

I am attaching the source code code, the original message and the host server response in hopes for a resolution today.

*** SOURCE CODE ***
Function _XmlPost2( cXml, oSay2 )

local loHyperlink
local cURL

TRY
// loHyperlink := TOLEAuto():New( "Microsoft.XmlHttp" )
loHyperlink := TOLEAuto():New( "MSXML2.XmlHttp" )
CATCH
MsgInfo( "unable to load TOLEAuto()" )
RETURN (.F.)
END

// cXML := memoread("teste.xml")

TRY
cURL := "http://1.2.3.4:9180/Web.EDI.Dispatcher.WebService/Web.EDI.Framework.asmx"
loHyperlink:Open( "POST", cURL, .f. )
CATCH
MsgInfo( "unable to connect to " + cUrl )
RETURN (.F.)
END

TRY
//loHyperlink:setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
loHyperlink:setRequestHeader("Content-Type", "text/xml")
CATCH
MsgInfo( "unable to set request header" )
RETURN (.F.)
END

TRY
//cxml := "xmlstring=" + cxml
loHyperlink:send( cXML )
CATCH
MsgInfo( "unable to send XML to " + cUrl )
RETURN (.F.)
END

if (At( "SUCCESS", upper(loHyperlink:responseText )) < 5)
msginfo("responseText" + CRLF + loHyperlink:responseText)
f_protokoll(loHyperlink:responseText)
else
msginfo("Senden war erfolgreich")
f_protokoll("Senden war erfolgreich")
endif

return nil

*** ORIGINAL XML MESSAGE ***
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<ServiceSchedules>
<Header>
<SenderId>CDMSOFTWARE</SenderId>
<ReceiverId>PASHAGROUP</ReceiverId>
<DateTimeStamp>2013-02-12T11:39:14</DateTimeStamp>
<ID>2013000031</ID>
<SchemaVersion>1.0</SchemaVersion>
</Header>
<Transactions>
<Transaction>
<MessageDate>2013-02-12T11:39:19</MessageDate>
<MessageFunction>REISSUE</MessageFunction>
<Carrier>HPG</Carrier>
<Schs Vsl="ALTAMIRA EXPRESS" Lloyds="8501426" Valid="Y" Voy="08W12" Service="MGX" >
<Sch Id="5E4E13FEECB819DB147C0B55B5528642" Act="C">
<Orig Type="POL" Code="GEN" Departs="2013-03-22T18:00:00" PortCutoff="2013-03-18T18:00:00" ></Orig>
<Dest Type="POD" Code="HOU" Arrives="2013-04-17T07:00:00" ></Dest>
</Sch>
<Sch Id="93950283D747605297CA07157CA2B56A" Act="C">
<Orig Type="POL" Code="GEN" Departs="2013-03-22T18:00:00" PortCutoff="2013-03-18T18:00:00" ></Orig>
<Dest Type="POD" Code="NOL" Arrives="2013-04-19T13:00:00" ></Dest>
</Sch>
</Schs>
</Transaction>
</Transactions>
</ServiceSchedules>

*** HOST SERVER RESPONSE ***
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<soap:Code>
<soap:Value>soap:Receiver
</soap:Value>
</soap:Code>
<soap:Reason>
<soap:Text xml:lang="en">
Server was unable to process request. ---&gt; Root element is missing.
</soap:Text>
</soap:Reason>
<soap:Detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>

*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Sending and Receiving XML Data
Posted: Thu Feb 14, 2013 05:55 PM

Darrell,

Why have you commented this from Otto's code ?

cxml := "xmlstring=" + cxml

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
Re: Sending and Receiving XML Data
Posted: Thu Feb 14, 2013 07:03 PM

Hi Antonio,

I have tried both ways with same response. I have also converted < to &lt; and > to &gt; and I am getting same response.

Sincerely,

*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
Re: Sending and Receiving XML Data
Posted: Thu Feb 14, 2013 08:46 PM

Antonio,

It seems that is more of a SOAP issue than data issue. Is there any documentation on using SOAP with FWH?

Thank you,

*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Sending and Receiving XML Data
Posted: Thu Feb 14, 2013 11:50 PM

Darrell,

If you google for: Server was unable to process request. ---&gt; Root element is missing

there are many references saying that the XML is incorrect. there is a problem with the root node.

I would suggest changing it to:
<?xml version="1.0" encoding="utf-8"?>

instead of yours:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
Re: Sending and Receiving XML Data
Posted: Fri Feb 15, 2013 12:10 AM

Hi Antonio,

I saw that too and I corrected but I am receiving the same error.

*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com

Continue the discussion