Sending and Receiving XML Data

Sending and Receiving XML Data

Postby cdmmaui » Tue Feb 12, 2013 7: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
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: Sending and Receiving XML Data

Postby Otto » Tue Feb 12, 2013 8:23 pm

This is working for me.
Best regards,
Otto

Code: Select all  Expand view


#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
//----------------------------------------------------------------------------//

 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: Sending and Receiving XML Data

Postby cdmmaui » Tue Feb 12, 2013 8:26 pm

Thank you Otto!
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: Sending and Receiving XML Data

Postby cdmmaui » Tue Feb 12, 2013 8: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
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: Sending and Receiving XML Data

Postby cdmmaui » Tue Feb 12, 2013 9: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
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: Sending and Receiving XML Data

Postby Otto » Tue Feb 12, 2013 10:54 pm

What is the response you get.

Code: Select all  Expand view
loHyperlink:responseText
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: Sending and Receiving XML Data

Postby cdmmaui » Thu Feb 14, 2013 4: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
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: Sending and Receiving XML Data

Postby Antonio Linares » Thu Feb 14, 2013 5:55 pm

Darrell,

Why have you commented this from Otto's code ?

cxml := "xmlstring=" + cxml
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42089
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Sending and Receiving XML Data

Postby cdmmaui » Thu Feb 14, 2013 7: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
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: Sending and Receiving XML Data

Postby cdmmaui » Thu Feb 14, 2013 8: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
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: Sending and Receiving XML Data

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42089
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Sending and Receiving XML Data

Postby cdmmaui » 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
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 86 guests