TFS_ANTIGUO/PrendarioDavivienda/ULA.Davivienda.WCFServiciosCobisCartera/ULA.Davivienda.WCFServiciosCobisCartera.DAL/outSoapConector.vb

339 lines
13 KiB
VB.net

Imports Ultimus.Utilitarios
Imports System.Xml
Imports System.IO
Imports System.Threading
Imports System.Globalization
Imports System.Xml.Serialization
Imports System.Configuration
Public Class outSoapConector
Public Shared log As LogFile = New LogFile()
Dim nfi As System.Globalization.NumberFormatInfo = New System.Globalization.NumberFormatInfo()
Dim arrPrefix As String() = New String() {}
Public Const I_FE_DDMMYYYY = 0
Public Const I_FE_MMDDYYYY = 1
Public Const I_FE_YYYYMMDD = 2
#Region "Constructor"
Public Sub New()
End Sub
#End Region
#Region "ObtienePrefijosNameSpace"
Public Shared Function ObtienePrefijosNameSpace(xmlDoc As MSXML2.DOMDocument, wsdl As String) As String()
Dim arrPrefix As String() = New String() {}
Dim nameWS As String = String.Empty
Dim xmlDocRec As MSXML2.DOMDocument
Dim nodeWS As MSXML2.IXMLDOMNode
Try
xmlDocRec = New MSXML2.DOMDocument()
xmlDocRec.async = False
xmlDocRec.validateOnParse = False
xmlDocRec.resolveExternals = False
nameWS = ObtieneNameWS(wsdl)
xmlDocRec.load(AppDomain.CurrentDomain().BaseDirectory & "/Parametros/NamespacesWebServices.xml")
'xmlDocRec.load("C:\inetpub\wwwroot\Proyectos\Ultimus\Generales\WS\integracionCobisGeneral\XmlSoap\NamespacesWebServices.xml")
nodeWS = xmlDocRec.documentElement.selectSingleNode(nameWS & "/namespaces")
If (Not IsNothing(nodeWS)) Then
ReDim arrPrefix(nodeWS.childNodes.length)
For i As Integer = 0 To arrPrefix.Length - 1
arrPrefix(i) = ""
Next
Dim nodeRoot As MSXML2.IXMLDOMNode = xmlDoc.documentElement
For Each atributo As MSXML2.IXMLDOMNode In nodeRoot.attributes
Dim _namespace As String = IIf(IsNothing(atributo.text), "", atributo.text)
Dim _prefix As String = IIf(IsNothing(atributo.baseName), "", atributo.baseName)
Dim arrSplit As String() = Split(_namespace, "//")
If (arrSplit.Length = 2) Then
Dim nodeAux As MSXML2.IXMLDOMNode = nodeWS.selectSingleNode(arrSplit(1))
If (Not IsNothing(nodeAux)) Then
Dim index As Integer = CInt(nodeAux.attributes(1).text)
arrPrefix(index) = _prefix
End If
End If
Next
End If
Catch ex As Exception
Throw New Exception("Error: [ObtienePrefijosNameSpace]:" & ex.Message)
End Try
Return arrPrefix
End Function
#End Region
#Region "ObtieneNameWS"
Private Shared Function ObtieneNameWS(wsdl As String) As String
Dim nameWS As String = String.Empty
Try
Select Case wsdl
Case "WS_COBIS_1",
"WS_COBIS_2",
"WS_COBIS_3",
"WS_COBIS_4",
"WS_COBIS_5",
"WS_COBIS_6",
"WS_COBIS_7",
"WS_COBIS_8",
"WS_COBIS_9",
"WS_COBIS_10",
"WS_COBIS_11"
nameWS = "wsUltimus"
Case Else
nameWS = ""
End Select
Catch ex As Exception
nameWS = ""
End Try
Return nameWS
End Function
#End Region
#Region "InvocaWebServiceSoap"
Public Shared Function InvocaWebServiceSoap(ByVal strSoapEnvelope As String,
ByRef strError As String,
ByRef arrPrefix As String(),
ByVal strProceso As String,
ByVal strUsuario As String) As Object
Dim xmlBaseSOAP As MSXML2.DOMDocument = New MSXML2.DOMDocument()
Dim root As MSXML2.IXMLDOMNode
Dim xmlNode As MSXML2.IXMLDOMNode
Dim strNodeWS As String
Dim strWebService As String
Dim strMethod As String
Dim strServerPuerto As String
Dim xmlDoc As MSXML2.DOMDocument = New MSXML2.DOMDocument()
xmlDoc.async = False
xmlDoc.validateOnParse = False
xmlDoc.resolveExternals = False
Dim xmlObj As MSXML2.DOMDocument = New MSXML2.DOMDocument()
xmlObj.async = False
xmlObj.validateOnParse = False
xmlObj.resolveExternals = False
xmlBaseSOAP.async = False
xmlBaseSOAP.validateOnParse = False
xmlBaseSOAP.resolveExternals = False
xmlBaseSOAP.loadXML(strSoapEnvelope)
root = xmlBaseSOAP.selectSingleNode("//soapenv:Envelope")
strNodeWS = xmlBaseSOAP.selectSingleNode("//soapenv:Envelope/soapenv:appinfo/wsdl").text
strWebService = System.Configuration.ConfigurationManager.AppSettings(strNodeWS)
'******************************************************
'OBTIENE EL PARAMETRO DEL NOMBRE Y PUERTO DEL SERBVIDOR
'******************************************************
strServerPuerto = ConfigurationManager.AppSettings("ServidorCobisPuerto")
strWebService = strWebService.Replace("[COBIS_SERVER]", strServerPuerto)
strMethod = xmlBaseSOAP.selectSingleNode("//soapenv:Envelope/soapenv:appinfo/metodo").text
Dim objXMLHttp As MSXML2.ServerXMLHTTP60
Dim strErr As String = String.Empty
Dim nResolveTimeout As Integer = 0
Dim nConnectTimeout As Integer = 0
Dim nSendTimeout As Integer = 0
Dim nReceiveTimeout As Integer = 0
Dim sResolveTimeout As String = String.Empty
Dim sConnectTimeout As String = String.Empty
Dim sSendTimeout As String = String.Empty
Dim sReceiveTimeout As String = String.Empty
Dim sSSLCertificateIgnoreERROR As String = String.Empty
Try
xmlNode = xmlBaseSOAP.selectSingleNode("//soapenv:Envelope/soapenv:appinfo")
xmlNode.parentNode.removeChild(xmlNode)
Try
log.EscribirArchivo("ULA.Davivienda.WCFServiciosCobisCartera", strProceso + "-" + strMethod + "-" + strUsuario + "-" + "IN_TYPE" + "-" + strSoapEnvelope)
sResolveTimeout = ConfigurationManager.AppSettings("soapSecondsToResolveTimeout")
sConnectTimeout = ConfigurationManager.AppSettings("soapSecondsToConnectTimeout")
sSendTimeout = ConfigurationManager.AppSettings("soapSecondsToSendTimeout")
sReceiveTimeout = ConfigurationManager.AppSettings("soapSecondsToReceiveTimeout")
nResolveTimeout = Integer.Parse(IIf(String.IsNullOrEmpty(sResolveTimeout), "60", sResolveTimeout.Trim())) * 1000
nConnectTimeout = Integer.Parse(IIf(String.IsNullOrEmpty(sConnectTimeout), "60", sConnectTimeout.Trim())) * 1000
nSendTimeout = Integer.Parse(IIf(String.IsNullOrEmpty(sSendTimeout), "60", sSendTimeout.Trim())) * 1000
nReceiveTimeout = Integer.Parse(IIf(String.IsNullOrEmpty(sReceiveTimeout), "60", sReceiveTimeout.Trim())) * 1000
Catch ex As Exception
Throw New Exception("Error al obtener la parametrización interna de conectividad del servicio. \n" & ex.Message)
End Try
'******************************************************
'REGISTRA EN LOG EL XML DE ENVIO A COBIS
'******************************************************
'outAuditoria.grabarLog(strProceso, strMethod, "", outAuditoria.IN_TYPE, xmlBaseSOAP.xml, "", "", strUsuario, "COBIS", "ARCHIVOLOG1", True)
objXMLHttp = New MSXML2.ServerXMLHTTP60()
objXMLHttp.setTimeouts(nResolveTimeout, nConnectTimeout, nSendTimeout, nReceiveTimeout)
'******************************************************
'INDICA SI EL ERROR EN EL CERTIFICADO SE IGNORA
'******************************************************
sSSLCertificateIgnoreERROR = ConfigurationManager.AppSettings("soapSSLCertificateIgnoreERROR")
If (sSSLCertificateIgnoreERROR.Trim().ToLower() = "true") Then
objXMLHttp.setOption(MSXML2.SERVERXMLHTTP_OPTION.SXH_OPTION_IGNORE_SERVER_SSL_CERT_ERROR_FLAGS, objXMLHttp.getOption(MSXML2.SERVERXMLHTTP_OPTION.SXH_OPTION_IGNORE_SERVER_SSL_CERT_ERROR_FLAGS))
End If
objXMLHttp.open("POST", strWebService, False, "", "")
objXMLHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8")
objXMLHttp.setRequestHeader("SOAPAction", strMethod)
objXMLHttp.send(xmlBaseSOAP.xml.ToString())
If (objXMLHttp.statusText <> "OK") Then
Throw New Exception("Error : " & objXMLHttp.status & " - " & objXMLHttp.responseText)
End If
If (Not objXMLHttp.responseXML Is Nothing) Then
xmlDoc.load(objXMLHttp.responseXML)
If (xmlDoc.parseError.errorCode = 0) Then
Dim resp As String = xmlDoc.text
'xmlObj.loadXML(xmlDoc.selectSingleNode("/soapenv:Envelope/soapenv:Body/ns13:" + strMethod + "Response").xml)
xmlObj.loadXML(xmlDoc.childNodes(1).childNodes(0).childNodes(0).xml)
arrPrefix = ObtienePrefijosNameSpace(xmlObj, strNodeWS)
'******************************************************
'REGISTRA EN LOG EL XML QUE SE RECIBIO DE COBIS
'******************************************************
log.EscribirArchivo("ULA.Davivienda.WCFServiciosCobisCartera", strProceso + "-" + strMethod + "-" + strUsuario + "-" + "OUT_TYPE" + "-" + xmlDoc.xml)
'outAuditoria.grabarLog(strProceso, strMethod, "", outAuditoria.OUT_TYPE, xmlDoc.xml, "", "", strUsuario, "COBIS", "ARCHIVOLOG1", True)
End If
End If
Catch ex As Exception
strErr = "Error: " & ex.Message
'******************************************************
'REGISTRA EN LOG EL ERROR QUE SE RECIBIO
'******************************************************
log.EscribirArchivo("ULA.Davivienda.WCFServiciosCobisCartera", strProceso + "-" + strMethod + "-" + strUsuario + "-" + "ERR_TYPE" + "-" + "[xmlRecuperado]--->" + IIf(String.IsNullOrEmpty(xmlDoc.xml), "No se recupero el xml de la interface.", xmlDoc.xml))
'outAuditoria.grabarLog(strProceso, strMethod, "", outAuditoria.ERR_TYPE, strErr + "[xmlRecuperado]--->" + IIf(String.IsNullOrEmpty(xmlDoc.xml), "No se recupero el xml de la interface.", xmlDoc.xml), "", "", strUsuario, "COBIS", "ARCHIVOLOG1", True)
Finally
If (IsNothing(xmlObj) Or (xmlObj.xml = "")) Then
strError &= "Error: no se puedo obtener el resultado de la consulta. Contacte al administrador del sistema."
End If
If (strErr.Trim() <> "") Then
strError &= strErr
End If
End Try
Return xmlObj
End Function
#End Region
#Region "AgregarNode"
Public Shared Function AgregarNodeValue(ByRef nodeFuente As MSXML2.IXMLDOMNode,
ByRef xmlPrincipal As MSXML2.DOMDocument,
ByRef nElementoChild As MSXML2.IXMLDOMNode,
ByRef nElementoFather As MSXML2.IXMLDOMNode,
ByRef aSoap As String,
ByRef aCampos As String) As Boolean
Dim booResult As Boolean = False
Try
nElementoChild = xmlPrincipal.createElement(aCampos)
nElementoChild.text = ObtieneValorNullable(nodeFuente, aSoap)
nElementoFather.appendChild(nElementoChild)
booResult = True
Catch ex As Exception
booResult = False
End Try
Return booResult
End Function
#End Region
#Region "ObtieneValorNullable"
Private Shared Function ObtieneValorNullable(nodeFuente As MSXML2.IXMLDOMNode, aSoap As String) As String
Dim outValor As String = String.Empty
Try
If nodeFuente.selectSingleNode(aSoap) Is Nothing Then
outValor = ""
Else
outValor = nodeFuente.selectSingleNode(aSoap).text
End If
Catch ex As Exception
outValor = ""
End Try
Return outValor
End Function
#End Region
'#Region "ObtenerParametroDesencriptado"
' Public Function ObtenerParametroDesencriptado(ByVal NomParametro As String) As String
' Dim strCadena As String = String.Empty
' Dim strError As String = String.Empty
' Dim objEncriptacion As New LibEncriptacion.Encriptacion
' Try
' strCadena = System.Configuration.ConfigurationManager.AppSettings(NomParametro)
' strCadena = objEncriptacion.getCadenaDesencriptada(strCadena, LibEncriptacion.Encriptacion.Llave.PUBLICA, strError)
' ObtenerParametroDesencriptado = strCadena
' Catch excError As Exception
' ObtenerParametroDesencriptado = ""
' Finally
' objEncriptacion = Nothing
' End Try
' End Function
'#End Region
End Class