Ver Mensaje Individual
  #2 (permalink)  
Antiguo 15/10/2008, 03:10
eks_500
 
Fecha de Ingreso: octubre-2008
Mensajes: 7
Antigüedad: 16 años, 7 meses
Puntos: 1
Solucionado: Adjuntar archivo a mensaje SOAP en ASP

Muy buenas, bueno pues con un poquito de esfuerzo ya salió, como ya hice anteriormente comparto el código para quien lo pueda necesitar en el futuro:

Código para el envío:

Código:
Set xmlhttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
	
' Crea un documento XML
set xml_dom = Server.CreateObject ("Msxml2.DOMDocument.4.0")
	
' Crea objeto ADO-stream
set ado_stream = Server.CreateObject("ADODB.Stream")

	
' Construyendo la cabecera del mensaje:
xml_dom.loadXML("<?xml version='1.0' encoding='utf-8' ?><body/>")

xml_dom.documentElement.setAttribute "xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance" 

xml_dom.documentElement.setAttribute "xmlns:dt","urn:schemas-microsoft-com:datatypes"

xml_dom.documentElement.setAttribute "xmlns:xsd","http://www.w3.org/2001/XMLSchema"

xml_dom.documentElement.setAttribute "xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/"
	
	
' Construyendo el cuerpo del mensaje:
'///////////////////   A R C H I V O    ///////////////////////////////////////

'/////////  N O M B R E   A R C H I V O			
set l_node2 = xml_dom.createElement("filename") ' Crea el parametro		
								
' Recupera el nombre del archivo a partir de la ruta:											
patharray = strReverse("C:\adfadfa.........\archivo.ext")									
names = Split (patharray ,"\")										
name=names(0)														
name=strReverse(name)																			
l_node2.nodeTypedValue = name ' Le asigna el valor							
xml_dom.documentElement.appendChild(l_node2) ' Lo añade al xml_dom			
							
'/////////  D A T O S   A R C H I V O											
set l_node1 = xml_dom.createElement("file") ' Crea el parametro			
l_node1.dataType = "bin.base64" ' Define el tipo de datos						
' Abre el archivo de lectura													
ado_stream.Type = 1  '// 1=adTypeBinary 									
ado_stream.Open() 													
ado_stream.LoadFromFile(uploadfile)									
								
' Escribe el archivo en el campo y lo añade al xml_dom									
l_node1.nodeTypedValue = ado_stream.Read(-1) '//  -1 = ReadAll				
ado_stream.Close()													
xml_dom.documentElement.appendChild(l_node1)					
'/////////////////////////////////////////////////////////////////////////////////////.
	
	
' we can create more XML nodes for multiple file upload

' send XML documento to Web server
xmlhttp.Open "POST", "http://" & Soap_Server & Soap_Path, False
xmlhttp.setRequestHeader "Man", "POST " & Soap_Path & " HTTP/1.1"
xmlhttp.setRequestHeader "Host", Soap_Server
	
xmlhttp.setRequestHeader "SOAPAction", Soap_Namespace & Soap_Action
	
xmlhttp.send(xml_dom)
Código para la recepción:

Código:
'//////////////////////////   C R E A R   O B J E T O S   ///////////////////////////////

' Create Stream Object						
set ado_stream = Server.CreateObject("ADODB.Stream")
								
' Create XMLDOM object and load it from request ASP object		
set xml_dom = Server.CreateObject("MSXML2.DOMDocument")		
xml_dom.load(request)										
'////////////////////////////////////////////////////////////////////////////////////////////.
   
'/////////////////////////  G U A R D A R   D A T O S   /////////////////////////////////
set filename = xml_dom.selectSingleNode("body/filename")	
set xml_file = xml_dom.selectSingleNode("body/file")		
'////////////////////////////////////////////////////////////////////////////////////////////.
   
'////////////////////////////   G R A B A R     A R C H I V O    1   ////////////////////////////////
' Open stream object and store XML node content into it   						
ado_stream.Type = 1  ' 1=adTypeBinary 							
ado_stream.open 											
ado_stream.Write xml_file.nodeTypedValue					
															
' Save uploaded file						
path = "C:\MyFolder\" & filename.nodeTypedValue				
					
ado_stream.SaveToFile path,2  ' 2=adSaveCreateOverWrite 			

ado_stream.close										
'////////////////////////////////////////////////////////////////////////////////////////////.
 
' Destroy COM object   
set ado_stream = Nothing 
set xml_dom = Nothing

Pues eso es todo, espero que a alguien le ayude

Saludos!!!!