Как я могу подключиться к службе WCF с помощью wsaddressing?
Я пытаюсь подключиться к службе WCF со следующей конфигурацией:
<wsp:Policy wsu:Id="WSHttpBinding_IService_policy"> <wsp:ExactlyOne> <wsp:All> <wsoma:OptimizedMimeSerialization xmlns:wsoma="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization"/> <sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"> <wsp:Policy> <sp:TransportToken> <wsp:Policy> <sp:HttpsToken RequireClientCertificate="false"/> </wsp:Policy> </sp:TransportToken> <sp:AlgorithmSuite> <wsp:Policy> <sp:Basic256/> </wsp:Policy> </sp:AlgorithmSuite> <sp:Layout> <wsp:Policy> <sp:Strict/> </wsp:Policy> </sp:Layout> <sp:IncludeTimestamp/> </wsp:Policy> </sp:TransportBinding> <sp:EndorsingSupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"> <wsp:Policy> <sp:SecureConversationToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient"> <wsp:Policy> <sp:BootstrapPolicy> <wsp:Policy> <sp:SignedParts> <sp:Body/> <sp:Header Name="To" Namespace="http://www.w3.org/2005/08/addressing"/> <sp:Header Name="From" Namespace="http://www.w3.org/2005/08/addressing"/> <sp:Header Name="FaultTo" Namespace="http://www.w3.org/2005/08/addressing"/> <sp:Header Name="ReplyTo" Namespace="http://www.w3.org/2005/08/addressing"/> <sp:Header Name="MessageID" Namespace="http://www.w3.org/2005/08/addressing"/> <sp:Header Name="RelatesTo" Namespace="http://www.w3.org/2005/08/addressing"/> <sp:Header Name="Action" Namespace="http://www.w3.org/2005/08/addressing"/> </sp:SignedParts> <sp:EncryptedParts> <sp:Body/> </sp:EncryptedParts> <sp:TransportBinding> <wsp:Policy> <sp:TransportToken> <wsp:Policy> <sp:HttpsToken RequireClientCertificate="false"/> </wsp:Policy> </sp:TransportToken> <sp:AlgorithmSuite> <wsp:Policy> <sp:Basic256/> </wsp:Policy> </sp:AlgorithmSuite> <sp:Layout> <wsp:Policy> <sp:Strict/> </wsp:Policy> </sp:Layout> <sp:IncludeTimestamp/> </wsp:Policy> </sp:TransportBinding> <sp:SignedSupportingTokens> <wsp:Policy> <sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient"> <wsp:Policy> <sp:WssUsernameToken10/> </wsp:Policy> </sp:UsernameToken> </wsp:Policy> </sp:SignedSupportingTokens> <sp:Wss11> <wsp:Policy/> </sp:Wss11> <sp:Trust10> <wsp:Policy> <sp:MustSupportIssuedTokens/> <sp:RequireClientEntropy/> <sp:RequireServerEntropy/> </wsp:Policy> </sp:Trust10> </wsp:Policy> </sp:BootstrapPolicy> </wsp:Policy> </sp:SecureConversationToken> </wsp:Policy> </sp:EndorsingSupportingTokens> <sp:Wss11 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"> <wsp:Policy/> </sp:Wss11> <sp:Trust10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"> <wsp:Policy> <sp:MustSupportIssuedTokens/> <sp:RequireClientEntropy/> <sp:RequireServerEntropy/> </wsp:Policy> </sp:Trust10> <wsaw:UsingAddressing/> </wsp:All> </wsp:ExactlyOne> </wsp:Policy> <wsdl:types>
Я попытался подключиться, но служба возвращает следующую ошибку:
System.ServiceModel.Security.MessageSecurityException: Incorrectly unprotected or unprotected error received on the other side. For the error code and further details, see Internal FaultException. ---> System.ServiceModel.FaultException: Unable to validate one or more security tokens in the message.
Что я уже пробовал:
Приложение.comfig
<system.serviceModel> <bindings> <wsHttpBinding> <binding name="WSHttpBinding_IService" messageEncoding="Mtom"> <security mode="TransportWithMessageCredential"> <transport clientCredentialType="None"/> <message clientCredentialType="UserName"/> </security> </binding> </wsHttpBinding> </bindings> <client> <endpoint address="https://*****/Service.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService" contract="SaniarpServices.IService" name="WSHttpBinding_IService"/> </client> </system.serviceModel>
Извлечение кода:
try { var c = new Services.ServiceClient(); var headers = new List<XmlQualifiedName>(); headers.Add(new XmlQualifiedName("Action", "http://www.w3.org/2005/08/addressing")); headers.Add(new XmlQualifiedName("MessageID", "http://www.w3.org/2005/08/addressing")); headers.Add(new XmlQualifiedName("ReplyTo", "http://www.w3.org/2005/08/addressing")); headers.Add(new XmlQualifiedName("To", "http://www.w3.org/2005/08/addressing")); headers.Add(new XmlQualifiedName("From", "http://www.w3.org/2005/08/addressing")); c.Endpoint.Behaviors.Add( new SignMessageHeaderBehavior(headers, "http://tempuri.org/IService/VerificaCF")); c.ClientCredentials.UserName.UserName = "test@tin.it"; Result ra = c.CheckCode("123"); if (ra.State == MessageStatusType.OK) { tbText.Text = "Connection ok: " + ra.TextState; } else { tbText.Text = "Connection ko: " + ra.TextState; } } catch (Exception ex) { tbText.Text = ex.ToString(); }