У меня ошибка: при проверке сообщения произошла ошибка безопасности.
Я не знаю, как опубликовать код . Он продолжает сообщать, что кода слишком много. Что мне делать?
Мне нужно подключиться к PUESC SENT.
endPointAddress = “https://te-ws.puesc.gov.pl/seap_wsChann ... gPort?wsdl ”;
ОК. Я начинаю с создания объекта AcceptDocumentResponse. AcceptDocumentResponse поступает из wsdl.
Код: Выделить всё
AcceptDocumentResponse acceptDocumentResponse;
acceptDocumentResponse = new AcceptDocumentResponse();
AcceptDocumentRequest acceptDocumentRequest = new AcceptDocumentRequest();
AcceptDocumentRequest1 acceptDocumentRequest1 = new AcceptDocumentRequest1();
acceptDocumentRequest.document = new documentType();
acceptDocumentRequest.document.content = new contentType();
acceptDocumentRequest.document.content.filename = "Message7.xml";
acceptDocumentRequest.document.content.mime = mimeType.applicationxml;
acceptDocumentRequest.document.content.Value = byteArray;
acceptDocumentRequest.document.targetSystems = new systemType[] { systemType.SENT };
acceptDocumentRequest1.AcceptDocumentRequest = acceptDocumentRequest;
Код: Выделить всё
CustomBinding binding = new CustomBinding();
var security = TransportSecurityBindingElement.CreateUserNameOverTransportBindingElement();
security.IncludeTimestamp = false;
security.DefaultAlgorithmSuite = SecurityAlgorithmSuite.Basic256;
security.AllowInsecureTransport = true;
security.EnableUnsecuredResponse = true;
security.MessageSecurityVersion = MessageSecurityVersion.WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10;
Ws-Security 1.1 Header Security не понятен
Код: Выделить всё
var encoding = new TextMessageEncodingBindingElement();
encoding.MessageVersion = MessageVersion.Soap11;
var transport = new HttpsTransportBindingElement();
transport.MaxReceivedMessageSize = 20000000;
binding.Elements.Add(security);
binding.Elements.Add(encoding);
binding.Elements.Add(transport);
Последняя строка кода выдает ошибку.
При проверке сообщения произошла ошибка безопасности.
Код: Выделить всё
DocumentHandlingPortClient client = new DocumentHandlingPortClient(binding, new EndpointAddress(url));
client.ChannelFactory.Endpoint.Behaviors.Remove();
client.ChannelFactory.Endpoint.Behaviors.Add(new CustomCredentials());
client.ClientCredentials.UserName.UserName = username;
client.ClientCredentials.UserName.Password = password;
acceptDocumentResponse = client.AcceptDocument(acceptDocumentRequest);
Base64(SHA-1(nonce + Created + Base64(SHA-1(пароль)) ))
I немного изменил WriteTokenCore.
Код: Выделить всё
protected override void WriteTokenCore(System.Xml.XmlWriter writer, System.IdentityModel.Tokens.SecurityToken token)
{
UserNameSecurityToken userToken = token as UserNameSecurityToken;
string tokennamespace = "o";
DateTime created = DateTime.UtcNow;
string createdStr = created.ToString("yyyy-MM-ddThh:mm:ssZ");
string nonce = Guid.NewGuid().ToString();
string basedPassword = string.Empty;
basedPassword = GetSHA1String(userToken.Password);
string passwordDigest = GetSHA1String(nonce + createdStr + basedPassword);
writer.WriteRaw(string.Format(
"" +
"" + userToken.UserName + "" +
"" +
passwordDigest + "" +
"" +
nonce + "" +
"" + createdStr + "", tokennamespace));
}
Однако он по-прежнему не работает. Понятия не имею, в чем дело.
Код: Выделить всё
protected string GetSHA1String(string phrase)
{
SHA1CryptoServiceProvider sha1Hasher = new SHA1CryptoServiceProvider();
byte[] hashedDataBytes = sha1Hasher.ComputeHash(Encoding.UTF8.GetBytes(phrase));
return Convert.ToBase64String(hashedDataBytes);
}
Документация в формате PDF описывает методы из wsdl, такие как AcceptDocumentResponse. К сожалению, нет примера того, как установить соединение.
Подробнее здесь: https://stackoverflow.com/questions/790 ... puesc-sent