Ajuda com webservice
Enviado: 21 Out 2015 16:52
Siga a orientação do José Quintas na mensagem postada acima, em 21 Out 2015 09:11.luiz antonio da silva escreveu:tá dando erro 1005 no exported variable ASYNC
Abraços,
Siga a orientação do José Quintas na mensagem postada acima, em 21 Out 2015 09:11.luiz antonio da silva escreveu:tá dando erro 1005 no exported variable ASYNC
Amigo, leia novamente a mensagem postada pelo José Quintas, pois conforme ele disse, não é obrigatório as linhas 22 até 30 do código que passei, então a linha onde tem o ASYNC não seria necessária.luiz antonio da silva escreveu:variable ASYNC
Código: Selecionar todos
/************************************************
* Compilar: hbmk2 soap.prg -lhbwin -lxhb
************************************************/
#include "hbcompat.ch"
#include "hbxml.ch"
#include "hbmxml.ch"
function main()
local cXml, cSoapAction, cWebservice, cOperation, cRetorno
cls
cWebservice := "https://www.econsig.com.br/central_homologa/services/HostaHostService/?wsdl"
cSoapAction := "urn:consultarMargem"
cOperation := "consultarMargem"
cXml := '<?xml version="1.0" encoding="utf-8"?>'+hb_eol()+;
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hos="HostaHostService">'+hb_eol()+;
'<soapenv:Header/>'+hb_eol()+;
'<soapenv:Body>'+hb_eol()+;
'<hos:consultarMargem>'+hb_eol()+;
'<hos:cliente>VIVER</hos:cliente>'+hb_eol()+;
'<hos:convenio>VIVER-BELOHORIZONTE</hos:convenio>'+hb_eol()+;
'<hos:usuario>viver_xml</hos:usuario>'+hb_eol()+;
'<hos:senha>viv12345</hos:senha>'+hb_eol()+;
'<hos:matricula>1000045</hos:matricula>'+hb_eol()+;
'<hos:cpf>677.673.871-86</hos:cpf>'+hb_eol()+;
'<hos:orgaoCodigo></hos:orgaoCodigo>'+hb_eol()+;
'<hos:estabelecimentoCodigo></hos:estabelecimentoCodigo>'+hb_eol()+;
'<hos:valorParcela>10</hos:valorParcela>'+hb_eol()+;
'<hos:senhaServidor></hos:senhaServidor>'+hb_eol()+;
'<hos:tokenAutServidor></hos:tokenAutServidor>'+hb_eol()+;
'<hos:loginServidor></hos:loginServidor>'+hb_eol()+;
'<hos:codVerba></hos:codVerba>'+hb_eol()+;
'<hos:servicoCodigo></hos:servicoCodigo>'+hb_eol()+;
'<hos:matriculaMultipla></hos:matriculaMultipla>'+hb_eol()+;
'</hos:consultarMargem>'+hb_eol()+;
'</soapenv:Body>'+hb_eol()+;
'</soapenv:Envelope>'
*--
oXML := TXMLDocument():New( cXml, HBXML_STYLE_NOESCAPE )
IF oXML:nError != HBXML_ERROR_NONE
alert( "xml com problema " + Str( oXML:nError ) )
RETURN
ENDIF
*--
cRetorno := MicrosoftXmlSoapPost( cXml, cSoapAction, cWebservice )
*--
HB_MemoWrit('retorno.xml',cRetorno)
? cRetorno
RETURN
*------------------------------------------------------
*------------------------------------------------------
FUNCTION MicrosoftXmlSoapPost( cXmlSoap, cSoapAction, cWebService )
LOCAL oServer, oDOMDoc, nCont, cRetorno := "*ERRO*", cXmlRetorno := ""
oServer := win_OleCreateObject( "MSXML2.ServerXMLHTTP.5.0")
oServer:Open( "POST", cWebService, .F. )
oServer:SetRequestHeader( "SOAPAction", cSoapAction )
oServer:SetRequestHeader( "Content-Type", "text/xml; charset=utf-8" )
oDOMDoc = Win_oleCREATEOBJECT("MSXML2.DOMDocument.5.0")
oDOMDoc:async = .F.
oDOMDoc:validateOnParse = .T.
oDOMDoc:resolveExternals := .F.
oDOMDoc:preserveWhiteSpace = .T.
oDOMDoc:LoadXML(cXmlSoap)
IF oDOMDoc:parseError:errorCode <> 0
? 'Erro: xML nao carregado'
RETURN Nil
ENDIF
TRY
oServer:send(oDOMDoc:xml)
CATCH oError
? 'Falha no envio do xML'
RETURN Nil
END
DO WHILE oServer:readyState <> 4
HB_milliseconds(500)
ENDDO
cRetorno := oServer:responseText
IF ValType( cRetorno ) == "C"
cXmlRetorno := cRetorno
ELSEIF cRetorno == NIL
cXmlRetorno := "*ERRO*"
ELSE
cXmlRetorno := ""
FOR nCont = 1 TO Len( cRetorno )
cXmlRetorno += Chr( cRetorno[ nCont ] )
NEXT
ENDIF
RETURN cXmlRetorno