viernes, 29 de septiembre de 2017

WebService CustomBinding

Ejemplo de invocación de un servicio web de tipo customBindig.

Posibles mensajes de Error si estuviese mal configurado:
InnerExceptionMessage
The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndPointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g.Message, Transport, None).

 public static void Metodo_Configura_customBinding()
        {
            Uri epUri = new Uri("https://[URL WebService].svc");
            CustomBinding binding = new CustomBinding();
            binding.Name = "[NombreInterfaceWebService]";
            binding.Elements.Add(new TextMessageEncodingBindingElement(MessageVersion.Soap12, System.Text.Encoding.UTF8));
            binding.Elements.Add(new HttpsTransportBindingElement());
            EndpointAddress endPoint = new EndpointAddress(epUri);

            using (var service = new NombreServiceClient(binding, endPoint))
            {
                try
                {
                    service.NombreDelMetodo(Parametros);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }

3 comentarios:

  1. Se ejecutó la prueba en un sistema ETL invocando a un servicio web sin problemas.

    ResponderEliminar
  2. De esta forma, se obtiene una configuración hecha en web.config pero realizada directamente en C#, en código en linea.

    Hay muchas configuraciones adicionales, que se pueden realizar a este nivel.

    ResponderEliminar
    Respuestas
    1. Así es, con esta configuración se omite el uso del web.config para configurar endpoint.

      Eliminar