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;
                }
            }
        }