Selon notre fournisseur, nous devons envoyer ce type d’en-tête:
ssortingng ssortingng
Mais lorsque j’ai vérifié avec Fiddler, j’ai envoyé cet en-tête:
uIDPo/HuqG5V/ExLj3CNfRenvjEAAAAA7YcLXCnGukqViuu2jfqDDp47VC4vVV1Omqf/X2lHIcsACQAA username password
J’utilise une liaison personnalisée comme suit (je l’ai utilisée sur un autre service Web avec la même méthode d’authentification et fonctionne correctement)
private static Binding CreateMultiFactorAuthenticationBinding() { HttpsTransportBindingElement httpTransport = new HttpsTransportBindingElement(); httpTransport.MaxReceivedMessageSize = int.MaxValue; //AddressHeader addressHeader = AddressHeader.CreateAddressHeader("Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", security, xmlObjectSerializer); CustomBinding binding = new CustomBinding(); binding.Name = "myCustomBinding"; TransportSecurityBindingElement messageSecurity = TransportSecurityBindingElement.CreateUserNameOverTransportBindingElement(); messageSecurity.IncludeTimestamp = false; messageSecurity.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12; messageSecurity.SecurityHeaderLayout = SecurityHeaderLayout.Ssortingct; messageSecurity.SetKeyDerivation(false); TextMessageEncodingBindingElement Quota = new TextMessageEncodingBindingElement(MessageVersion.Soap11, System.Text.Encoding.UTF8); Quota.ReaderQuotas.MaxDepth = 32; Quota.ReaderQuotas.MaxSsortingngContentLength = Int32.MaxValue; Quota.ReaderQuotas.MaxArrayLength = 16384; Quota.ReaderQuotas.MaxBytesPerRead = 4096; Quota.ReaderQuotas.MaxNameTableCharCount = 16384; binding.Elements.Add(Quota); binding.Elements.Add(messageSecurity); binding.Elements.Add(httpTransport); return binding; } private WaybillManagementPOD GetClient() { CustomBinding customBinding = (CustomBinding)CreateMultiFactorAuthenticationBinding(); EndpointAddress endpointAddress = new EndpointAddress(this.EndPointAddr); WaybillManagementPOD proxy = ChannelFactory.CreateChannel(customBinding, endpointAddress); ServicePointManager.ServerCertificateValidationCallback = (obj, certificatee, chain, errors) => true; ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3; ChannelFactory _bankChannel = new ChannelFactory(customBinding, this.EndPointAddr); ChannelFactory channelFactory = null; WaybillManagementPOD client = null; channelFactory = new ChannelFactory(customBinding, endpointAddress); channelFactory.Credentials.UserName.UserName = this.WsUser; channelFactory.Credentials.UserName.Password = this.WsPass; client = channelFactory.CreateChannel(); return client; } public registrarCartaDePorteResponse registrarCP(ParametrosRegistro reg) { WaybillManagementPOD cliente = GetClient(); try { registrarCartaDePorte req = new registrarCartaDePorte(reg); registrarCartaDePorteResponse resp = cliente.registrarCartaDePorte(req); return resp; } catch (Exception e) { throw e; } }
PS: Je sais que ce n’est pas une bonne pratique de contourner le certificate SSL, mais pour le moment, c’est pour le test seulement.
Ni mon fournisseur, ni moi-même ne pouvons déterminer d’où vient l’erreur ou quelle en est la cause, que ce soit dans le type de liaison ou autre chose.
J’ai finalement utilisé comme suggéré ici le moyen correct de communiquer avec WSSE Usernametoken pour le service Web SOAP
Bob 1234
De plus, j’appelle maintenant le service Web directement depuis la classe créée par la référence WCF, au lieu d’utiliser la classe personnalisée ci-dessus.
De plus, pour copier les informations de la solution de service vers la solution d’interface utilisateur, voir ici: Erreur WCF – Impossible de trouver l’élément de noeud final par défaut faisant référence au contrat ‘UserService.UserService’.
Maintenant, tout semble bien fonctionner.