Dear Roger,
in the folder \exp20\Samples\Soap
you have provided examples for SOAP that are executed via Xb2NET.LIB/DLL technology.
Did you do that because Alaska Xbase++ with the HTTPClient() class
cannot execute SOAP?
I am asking this for the following reason:
I am trying to use HTTPClient for SOAP, but I am not succeeding at all.
On the forums I came across a PRG in which the author gives an example of using
the HTTPClient() class for SOAP communication.
I am sending that PRG as an attachment to this question.
I tried to use the code from that PRG file in different variants, but I did not
get any results. In the end, I began to suspect the following: CAN Xbase++
with the HTTPClient() class communicate with a SOAP server?
Especially since the documentation for Xbase++ does not contain a single example for SOAP.
Please answer.
Roger and SOAP and HTTPClient() and Xb2NET
- slobodan1949
- Posts: 94
- Joined: Mon Apr 25, 2011 8:57 am
- Location: SERBIA
- Contact:
Roger and SOAP and HTTPClient() and Xb2NET
- Attachments
-
- SOAP_TEST_HTTPClient.zip
- (1.97 KiB) Downloaded 88 times
Re: Roger and SOAP and HTTPClient() and Xb2NET
Yes, HttpClient can do that, but you have to create the SOAP envelope by yourself. If you POST that (and it's correct), it will work. This (still) is easier with Xb2.Net, and Roger created that sample years before HttpClient came up.
Best regards,
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
Re: Roger and SOAP and HTTPClient() and Xb2NET
I wrote a program that uses HttpClient to connect to SOAP services which are used by the New York City Taxi business.
Here is some sample code:
Here is some sample code:
Code: Select all
CLASS Soap20
EXPORTED:
VAR soapUrl
VAR soapPort
VAR soapMethod
VAR soapAction
VAR soapRequest
VAR soapResponse
VAR soapClient
VAR soapXb2Net
VAR action
* -------------
INLINE METHOD Init( cHost, cSoapAction, cSoapMethod )
::soapXb2Net := .f.
::soapURL := cHost
::soapAction := cSoapAction
::soapMethod := cSoapMethod
::soapPort := 443
RETURN self
* -------------
INLINE METHOD Send( cEnvelope, oVars, cDelim, oRootNode )
LOCAL i, aVars, cVarName, cVarValue, cResult, oAgent, oResult, cProcName, cXmlFile
DEFAULT cDelim := '%'
aVars := oVars:classDescribe()[3]
::soapRequest := cEnvelope
FOR i := 1 TO Len(oVars)
cVarname := aVars[i,1]
cVarValue := DC_XtoC(oVars[i])
::soapRequest := Strtran(::soapRequest, cDelim + cVarName + cDelim, cVarValue)
NEXT
IF ::soapXb2Net
oAgent := xbSoapEnvelope():new()
oAgent:recvTimeout(5000)
oAgent:SetStyle( SOAP_STYLE_DOCUMENT/*, SOAP_BINDING_LITERAL*/ )
oAgent:deserializeResponse := .t.
oResult := oAgent:Execute( ::soapURL, ::soapMethod, ::soapAction, ::soapRequest )
::soapResponse := oResult:asString()
ELSE
::soapClient := HttpClient():new( ::soapURL )
::soapClient:setAcceptType( "text/xml" )
::soapClient:setAcceptCharSet( "utf-8" )
IF !Empty(::action)
::soapClient:httpRequest:setHeader( "Content-Type", 'text/xml;action=' + ::action)
ELSE
::soapClient:httpRequest:setHeader( "Content-Type", 'text/xml' )
ENDIF
IF !Empty(::soapAction)
::soapClient:httpRequest:setHeader( "SOAPAction", ::soapAction )
ELSEIF !Empty(::action)
ENDIF
::soapClient:httpRequest:setMethod( "POST" )
::soapClient:httpRequest:setContent( ::soapRequest )
::soapResponse := ::soapClient:send()
ENDIF
oRootNode := DC_Xml2ObjectTree(::soapResponse)
IF Valtype(oRootNode) == 'O'
cProcName := ProcName(2)
cXmlFile := cProcName + '_' + Dtos(Date()) + '_' + Strtran(Time(),':','') + '.xml'
oRootNode:childList()[1]:writeXML(cXmlFile)
DC_SpawnUrl(cXmlFile)
ENDIF
RETURN ::soapResponse
ENDCLASS
The eXpress train is coming - and it has more cars.
- slobodan1949
- Posts: 94
- Joined: Mon Apr 25, 2011 8:57 am
- Location: SERBIA
- Contact:
Re: Roger and SOAP and HTTPClient() and Xb2NET
Roger, hvala na dobrom kodu.
Tome, hvala na odgovoru. Sada imam motiv i neću odustati od daljih pokušaja.
Tome, hvala na odgovoru. Sada imam motiv i neću odustati od daljih pokušaja.
- slobodan1949
- Posts: 94
- Joined: Mon Apr 25, 2011 8:57 am
- Location: SERBIA
- Contact:
Re: Roger and SOAP and HTTPClient() and Xb2NET
Roger, thanks for the good code.
Tom, thanks for the answer. Now I have a motive and I will not give up on further attempts.
Tom, thanks for the answer. Now I have a motive and I will not give up on further attempts.
- slobodan1949
- Posts: 94
- Joined: Mon Apr 25, 2011 8:57 am
- Location: SERBIA
- Contact:
Re: Roger and SOAP and HTTPClient() and Xb2NET
I successfully got the following result. Maybe someone will need it for similar projects.
I am attaching the tested code.
I am attaching the tested code.
- Attachments
-
- SOAP Xbase++ and SOAP and RESTFUL.zip
- (1.04 MiB) Downloaded 105 times