FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Ayuda con autenticaci贸n SOAP
Posts: 989
Joined: Thu Nov 24, 2005 03:01 PM
Ayuda con autenticaci贸n SOAP
Posted: Wed Sep 17, 2014 08:47 AM
Hola gente,

estoy tratando de usar un servicio WEB via MSSoap y Harbour, y tengo todo bastante cocinado con excepci贸n de un detalle: autenticaci贸n.
El c贸digo es el que sigue, pero me falta la autenticaci贸n porque no se como poner el usuario y la contrase帽a, no encuentro el equivalente de las instrucciones de VB

el codigo
Code (fw): Select all Collapse
聽 聽 聽 TRY
聽 聽 聽 聽 聽oSoap := CreateObject( "MSSOAP.SoapClient30" )
聽 聽 聽 聽 聽oSoap:msSoapInit( "http://localhost:8089/open/services/AbsenceFileService?wsdl" )
聽 聽 聽 聽 聽// oSoap:msSoapInit( "http://user:passw@localhost:8089/open/services/AbsenceFileService?wsdl" )
聽 聽 聽 聽 聽// si trato de poner el usuario en la URL, falla la funcion msSoapInit
聽 聽 聽 聽 聽oSoap:ClientProperty("ServerHTTPRequest")
聽 聽 聽 聽 聽// en VBA el usuario y la contrase帽a se ponen as铆
聽 聽 聽 聽 聽// oSoap:ConnectorProperty("AuthUser" ) = 'user'
聽 聽 聽 聽 聽// oSoap:ConnectorProperty("AuthPassword") = 'passwd'
聽 聽 聽 聽 聽// Y es lo que no he sabido reemplazar con Harbour
聽 聽 聽 聽 聽// Cosas que he probado:

聽 聽 聽 聽 聽oSoap:ConnectorProperty:AuthUser:= 'user'
聽 聽 聽 聽 聽// Argument Error

聽 聽 聽 聽 聽oSoap:ConnectorProperty:AuthUser( 'user' )
聽 聽 聽 聽 聽// Argument Error

聽 聽 聽 聽 聽oSoap:ConnectorProperty("AuthUser", 'user' )
聽 聽 聽 聽 聽// Argument Error

聽 聽 聽 聽 聽oSoap:ConnectorProperty("AuthUser") := 'user' 
聽 聽 聽 聽 聽// No compila, invalid lValue

聽 聽 聽 聽 聽oSoap:ConnectorProperty("AuthUser"):Value := 'user' 
聽 聽 聽 聽 聽// No exported variable

聽 聽 聽 聽 聽oSoap:AuthUser:= 'user'
聽 聽 聽 聽 聽// No exported variable

聽 聽 聽 聽 聽MsgInfo( ValType( oSoap:ConnectorProperty("AuthUser") ) ) // -> '' en blanco, no tiene tipo, ni siquiera 'U'

聽 聽 聽 聽 聽oSoap:ConnectorProperty("AuthPassword"):Value := 'passwd'
聽 聽 聽 聽 聽// Not exported variable

聽 聽 聽 CATCH oError
聽 聽 聽 聽 聽MsgStop( oError )
聽 聽 聽 聽 聽Quit
聽 聽 聽 END TRY


La cosa es esa: 驴como se escribe el equivalente del c贸digo VB "oSoap:ConnectorProperty("AuthUser" ) = 'user'" ?

Hay alguna otra forma de usar SOAP ?

He buscado en el foro pero no he encontrado nada relacionado con autenticaci贸n.
Saludos
Carlos Mora
http://harbouradvisor.blogspot.com/
StackOverflow http://stackoverflow.com/users/549761/carlos-mora
鈥淚f you think education is expensive, try ignorance"
Posts: 120
Joined: Wed Mar 11, 2009 07:32 PM
Re: Ayuda con autenticaci贸n SOAP
Posted: Wed Sep 17, 2014 04:38 PM
Hola carlos buenos dias


aver si te sirve este ejemplo
y en ejemplo Vb que pones las propiedades te lo genera ya el vb y en fivewin ay que hacerlo paso a paso

en este ejemplo se conecta a un servidor se le da el usuario y contrase帽a y la forma de llamarlo es consultando tu url ayi vienen todas las propiedadades
si el usuario es bueno madan el servicio si no regresa que el usuario no existe

saludos



Code (fw): Select all Collapse
#include "FiveWin.ch"

Function Main()
local url
local doc, ohttp, response, cxml
URL:="https://www.sunat.gob.pe/ol-it-wsconscpegem/billConsultService"
doc:=CreateObject( "MSXML2.DOMDocument" )
ohttp:=createobject( "Microsoft.XMLHTTP")

ohttp:Open( "POST" , URL , .F. )
ohttp:SetRequestHeader("Content-Type" ,"text/xml; charset=utf-8")
Ohttp:SetRequestHeader( "SOAPAction" , "getStatus" )

//autenticar(string,string) funcion que se encuntra en el servidor WS


cxml:="" 聽 聽//'<?xml version="1.0" encoding="UTF-8"?>'
cxml:=cxml+'<soapenv:Envelope xmlns:ser="http://service.sunat.gob.pe"'+chr(13)
cxml:=cxml+'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"'+CHR(13)
cxml:=cxml+'xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">'+CHR(13)
cxml:=cxml+"<soapenv:Header>"
cxml:=cxml+"<wsse:Security>"
cxml:=cxml+"<wsse:UsernameToken>"
cxml:=cxml+"<wsse:Username>xxxx</wsse:Username>"
cxml:=cxml+"<wsse:Password>xxxx</wsse:Password>"
cxml:=cxml+"</wsse:UsernameToken>"
cxml:=cxml+"</wsse:Security>"
cxml:=cxml+"</soapenv:Header>"
cxml:=cxml+"<soapenv:Body>"
cxml:=cxml+"<ser:getStatus>"
cxml:=cxml+"<rucComprobante>xxxxxx</rucComprobante>"
cxml:=cxml+"<tipoComprobante>xxxx</tipoComprobante>"
cxml:=cxml+"<serieComprobante>xxxx</serieComprobante>"
cxml:=cxml+"<numeroComprobante>xxxx</numeroComprobante>"
cxml:=cxml+"</ser:getStatus>"
cxml:=cxml+"</soapenv:Body>"
cxml:=cxml+"</soapenv:Envelope>"
doc:LoadXML( cXml ) //carga el documento a xml
? cxml
ohttp:send(doc:xml)
response:= ohttp:responseText

?response

return .t.
Benjamin Casarrubias Moreno
Cd. Obreg贸n, Sonora, M茅xico
chino72vale@hotmail.com
Fivewin 24.04, Harbour 3.3, xharbour 1.2.1, Fivelinux, Visual Estudio 2022
Oracle Api Rest, SDK Contpaq, Facturaci贸n Electr贸nica, XML DIOT 2025
Posts: 989
Joined: Thu Nov 24, 2005 03:01 PM
Re: Ayuda con autenticaci贸n SOAP
Posted: Thu Sep 18, 2014 07:34 AM

Hola benjiben,

muy bueno tu ejemplo, voy a ahacer pruebas a ver si puedo escribir manualmente toda la llamada xml al servicio.

Muchas gracias,

Saludos
Carlos Mora
http://harbouradvisor.blogspot.com/
StackOverflow http://stackoverflow.com/users/549761/carlos-mora
鈥淚f you think education is expensive, try ignorance"

Continue the discussion