Publicações

SOAP utilizando asp classico

<%

Dim objXMLHTTP : set objXMLHTTP = Server.CreateObject("Msxml2.XMLHTTP.3.0")
Dim strRequest, strResult, strFunction, strURL, strAcao

Set objFuncao = Server.CreateObject("DLLFUNCOES.Funcoes")
set objCN = Server.Createobject("DLLCONEXAO.Conexao")
Set RS = Server.CreateObject("ADODB.Recordset")

'URL to SOAP namespace and connection URL
strAcao = "https://www2.siteteste.com.br/integracao/IDados/GetInformacoes"
strURL = "https://www2.siteteste.com.br/Integracao/Dados.svc"

strRequest = "
<?xml version='1.0' encoding='utf-8' ?>
" _
& "<soapenv:Envelope xmlns:soapenv='https://schemas.xmlsoap.org/soap/envelope/' xmlns:int='https://www2.siteteste.com.br/integracao/'>
    " _
    & "<soapenv:Header xmlns:wsa='https://www.w3.org/2005/08/addressing'>
        " _
        & "<token xmlns='https://CF.Integracao'>1234567-1b23-5sd66-8888-bc62d0cac2dc</token>" _
        & "<wsa:To>https://https://www2.siteteste.com.br/Integracao/Dados.svc</wsa:To>" _
        & "
    </soapenv:Header>" _
    & "   <soapenv:Body>
        " _
        & "      <int:GetDados />" _
        & "
    </soapenv:Body>" _
    & "
</soapenv:Envelope>"

objXMLHTTP.open "post", "" & strURL & "", False

objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
objXMLHTTP.setRequestHeader "Content-Length", Len(strRequest)

objXMLHTTP.setRequestHeader "SOAPAction", strAcao

Call objXMLHTTP.send(strRequest)
strResult = objXMLHTTP.responseText

'DESFRAGMENTA RESULTADO PARA OBTER OS DADOS PARA TRATAR -------------------------------------------------------

dim str

'LIMPA TAGS
str = replace(strResult,"<","
<br>")
str = replace(str, "a:","")
str = replace(str, "/Nome>
<br>","")
str = replace(str, "/UF>
<br>","")
str = replace(str, "/TOEmpresa>
<br>","")
str = replace(str, "/CodigoEmpresa>
<br>","")
str = replace(str, "/Id>
<br>","")
str = replace(str, "TOEmpresa>","")
str = replace(str, ">",": ")

'LIMPA HEADER
str = replace(str, "s:Envelope xmlns:s=""https://schemas.xmlsoap.org/soap/envelope/"">
<br>","")
str = replace(str, "s:Body>
<br>","")
str = replace(str, "GetEmpresasResponse xmlns=""https://www2.siteteste.com.br/Integracao/"">
<br>","")
str = replace(str, "GetEmpresasResult xmlns:a=""https://schemas.datacontract.org/2004/07/Cf.Integracao.Negocio.TO"" xmlns:i=""https://www.w3.org/2001/XMLSchema-instance"">
<br>","")

'AJUSTA SEPARADORES
str = replace(str, "CodigoEmpresa>","CodigoEmpresa: ")
str = replace(str, "Id>","Id: ")
str = replace(str, "Nome>","Nome: ")
str = replace(str, "UF>","UF: ")

'APRESENTA UMA UNICA EMPRESA POR LINHA
str = replace(str,"
<br>","|")
str = replace(str, "CodigoEmpresa", "
<br>CodigoEmpresa")
str = replace(str, "||","")

'CRIA OS COMANDOS DE INSERT PARA A TABELA  --------------------------------------------------------------

Cd_Empresa = 0           'PODE SER DESCONSIDERADO O CÓDIGO NA TABELA TEMPORARIA
Id_Usuario = "Sistemas"

str = replace(str,"
<br>","¬")
str_array = split(str,"¬")

    'Pega o ultimo cd Empresa na tabela
    strCont = "Select Max(cd_Empresa) Valor from tabela_Empresa"
    set RSCont = objCN.consultar(strConn, strCont)

    vCd_Empresa = RSCont("Valor")

    for i = 0 to ubound(str_array)

        if trim(str_array(i)) <> "" then

            Aux_array = split(str_array(i),"|")

            Aux_array2 = split(Aux_array(2),":")
            Nome = trim(Aux_array2(1))

            Aux_array2 = split(Aux_array(3),":")
            Uf_Empresa = trim(Aux_array2(1))

            Aux_array2 = split(Aux_array(1),":")
            Cd_CF = trim(Aux_array2(1))

            str = "select count(*) novo from tabela_Empresa where cd_cf =  " & Cd_CF & ""
            set RS = objCN.consultar(strConn, str)

            if RS("novo") < 1 Then
                comandos_insert = ""
                vCd_Empresa = vCd_Empresa + 1
                Nome = Replace(Nome,"nil=""true""/>","")
                Uf_Empresa = Replace(Uf_Empresa,"nil=""true""/>","")

                StrCmd = "insert into tabela_Empresa (Cd_Empresa, Nome, Uf_Empresa, Id_Usuario, Cd_CF) values (" & vCd_Empresa & ", '" & Nome & "', '" & Uf_Empresa & "', '" & Id_Usuario & "', " & Cd_CF & ");"
                objCN.Executar strConn, strCmd

            end if

        end if

    next

%>



whatsapp instagram