consumir SOAP en delphi
Publicado por Marco (1 intervención) el 26/12/2021 18:36:09
Hola a todos del foro
Acudo a ustedes por que no tengo experiencia en consumir los servicios Web y espero de que me puedan ayudar esto es el ejemplo en NETCORE
Nota.- La inclusión del Token de la petición SOAP debe hacerse en la cabecera HTTP y no así en la cabecera XML del request
Para efectos ilustrativos, se ejemplifica en los siguientes lenguajes:
using System;
using System.ServiceModel;
using ServiceReference;
using System.Xml;
using System.Threading.Tasks;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Channels;
namespace client
{
class Program
{
private static string endpointAddress = "https://pilotosiatservicios.impuestos.gob.bo/v1/FacturacionCodigos?wsdl";
static void Main(string[] args)
{
string token = "TOKEN";
BasicHttpBinding binding = new BasicHttpBinding
{
SendTimeout = TimeSpan.FromSeconds(1000),
MaxBufferSize = int.MaxValue,
MaxReceivedMessageSize = int.MaxValue,
AllowCookies = true,
ReaderQuotas = XmlDictionaryReaderQuotas.Max
};
binding.Security.Mode = BasicHttpSecurityMode.Transport; // https
//binding.Security.Mode = BasicHttpSecurityMode.None; // http
EndpointAddress address = new EndpointAddress(endpointAddress);
ServicioFacturacionCodigosClient servicio = new ServicioFacturacionCodigosClient(binding, address);
servicio.Endpoint.EndpointBehaviors.Add(new CustomAuthenticationBehaviour($"Token {token}"));
try {
Task<verificarComunicacionResponse> resp = servicio.verificarComunicacionAsync();
resp.Wait();
Console.WriteLine(resp.Result.@return);
} catch (Exception e) {
Console.WriteLine($"{e.Message}");
}
}
}
public class CustomMessageInspector : IClientMessageInspector
{
readonly string _authToken;
public CustomMessageInspector(string authToken)
{
_authToken = authToken;
}
public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
var reqMsgProperty = new HttpRequestMessageProperty();
reqMsgProperty.Headers.Add("Authorization", _authToken);
request.Properties[HttpRequestMessageProperty.Name] = reqMsgProperty;
return null;
}
public void AfterReceiveReply(ref Message reply, object correlationState)
{ }
}
}
Acudo a ustedes por que no tengo experiencia en consumir los servicios Web y espero de que me puedan ayudar esto es el ejemplo en NETCORE
Nota.- La inclusión del Token de la petición SOAP debe hacerse en la cabecera HTTP y no así en la cabecera XML del request
Para efectos ilustrativos, se ejemplifica en los siguientes lenguajes:
using System;
using System.ServiceModel;
using ServiceReference;
using System.Xml;
using System.Threading.Tasks;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Channels;
namespace client
{
class Program
{
private static string endpointAddress = "https://pilotosiatservicios.impuestos.gob.bo/v1/FacturacionCodigos?wsdl";
static void Main(string[] args)
{
string token = "TOKEN";
BasicHttpBinding binding = new BasicHttpBinding
{
SendTimeout = TimeSpan.FromSeconds(1000),
MaxBufferSize = int.MaxValue,
MaxReceivedMessageSize = int.MaxValue,
AllowCookies = true,
ReaderQuotas = XmlDictionaryReaderQuotas.Max
};
binding.Security.Mode = BasicHttpSecurityMode.Transport; // https
//binding.Security.Mode = BasicHttpSecurityMode.None; // http
EndpointAddress address = new EndpointAddress(endpointAddress);
ServicioFacturacionCodigosClient servicio = new ServicioFacturacionCodigosClient(binding, address);
servicio.Endpoint.EndpointBehaviors.Add(new CustomAuthenticationBehaviour($"Token {token}"));
try {
Task<verificarComunicacionResponse> resp = servicio.verificarComunicacionAsync();
resp.Wait();
Console.WriteLine(resp.Result.@return);
} catch (Exception e) {
Console.WriteLine($"{e.Message}");
}
}
}
public class CustomMessageInspector : IClientMessageInspector
{
readonly string _authToken;
public CustomMessageInspector(string authToken)
{
_authToken = authToken;
}
public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
var reqMsgProperty = new HttpRequestMessageProperty();
reqMsgProperty.Headers.Add("Authorization", _authToken);
request.Properties[HttpRequestMessageProperty.Name] = reqMsgProperty;
return null;
}
public void AfterReceiveReply(ref Message reply, object correlationState)
{ }
}
}
Valora esta pregunta


0