У меня есть приложение Ruby on Rails, которое должно заменить существующий веб-сервис SOAP, чтобы позволить стороннему приложению вызывать его. Существует существующий WSDL с одной операцией, которую мне нужно воспроизвести. У меня нет доступа к серверу, на котором работает существующий веб-сервис, поэтому я не могу нажать на него curl
и проверить его ответ.
Устаревшее приложение. NET 4.0, использующее WCF с SecurityMode. TransportWithMessageCredential. У меня есть приложение, которое имитирует его, но у меня нет доступа к исходному коду.
Приложение подключается к моей службе SOAP, чтобы выполнить запрос RequestSecurityToken с использованием учетных данных UserName. Пока все хорошо.
Я читал это: http://specs.xmlsoap.org/ws/2005/02/trust/WS-Trust.pdf и http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512/ws-secureconversation-1.3-os.html. Есть много дополнительных элементов в ответе. Я нашел этот вопрос: Как передать учетные данные сообщения - TransportWithMessageCredential - Нет учетных данных в запросе SOAP , который включает RequestSecurityTokenResponse, который работал для автора. Я использовал этот ответ в качестве шаблона:
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/trust/RSTR/SCT</a:Action>
<a:RelatesTo>#{message_id}</a:RelatesTo>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<u:Timestamp u:Id="_0">
<u:Created>#{xml_datetime(response_created_at)}</u:Created>
<u:Expires>#{xml_datetime(response_expires_at)}</u:Expires>
</u:Timestamp>
</o:Security>
</s:Header>
<s:Body>
<t:RequestSecurityTokenResponse xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">
<t:TokenType>http://schemas.xmlsoap.org/ws/2005/02/sc/sct</t:TokenType>
<t:RequestedSecurityToken>
<c:SecurityContextToken u:Id="uuid-#{security_context_token_id}-8" xmlns:c="http://schemas.xmlsoap.org/ws/2005/02/sc">
<c:Identifier>urn:uuid:#{security_context_token}</c:Identifier>
</c:SecurityContextToken>
</t:RequestedSecurityToken>
<t:RequestedAttachedReference>
<o:SecurityTokenReference xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<o:Reference ValueType="http://schemas.xmlsoap.org/ws/2005/02/sc/sct" URI="\#uuid-#{security_context_token_id}-8"/>
</o:SecurityTokenReference>
</t:RequestedAttachedReference>
<t:RequestedUnattachedReference>
<o:SecurityTokenReference xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<o:Reference URI="urn:uuid:#{security_context_token}" ValueType="http://schemas.xmlsoap.org/ws/2005/02/sc/sct"/>
</o:SecurityTokenReference>
</t:RequestedUnattachedReference>
<t:RequestedProofToken>
<t:ComputedKey>http://schemas.xmlsoap.org/ws/2005/02/trust/CK/PSHA1</t:ComputedKey>
</t:RequestedProofToken>
<t:Entropy>
<t:BinarySecret u:Id="uuid-#{binary_secret_id}-9" Type="http://schemas.xmlsoap.org/ws/2005/02/trust/Nonce">#{binary_secret}</t:BinarySecret>
</t:Entropy>
<t:Lifetime>
<u:Created>#{xml_datetime(response_created_at)}</u:Created>
<u:Expires>#{xml_datetime(response_expires_at)}</u:Expires>
</t:Lifetime>
<t:KeySize>256</t:KeySize>
</t:RequestSecurityTokenResponse>
</s:Body>
</s:Envelope>
Когда у меня есть устаревшее приложение, подключенное к моему веб-сервису, я могу подтвердить, что ответ имеет контент, созданный по шаблону выше, и я могу подтвердить, что XML вывод представляется действительным (без ошибок пространства имен или несоответствия тегов). Мой веб-сервер возвращает код ответа 200.
Устаревшее приложение использует следующие параметры:
WSHttpBinding wsHttpBinding = new WSHttpBinding(SecurityMode.TransportWithMessageCredential);
wsHttpBinding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
Клиент, созданный с помощью wsHttpBinding, имеет следующие параметры:
if (ServicePointManager.SecurityProtocol == (SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls))
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls12;
if (!this.cbServerCertificateValidation.Checked)
ServicePointManager.ServerCertificateValidationCallback += (RemoteCertificateValidationCallback)
{
return true;
};
Когда выполняется вызов веб-службы, возникает сообщение CommunicationException:
The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.
Также возникает вопрос об этом: Объект связи, System.ServiceModel.Channels.ServiceChannel, не может использоваться для связи , которая указывает, что клиент считает, что сервер каким-то образом неисправен. Я думаю, это потому, что в моем RequestSecurityTokenResponse либо отсутствуют элементы, либо содержатся элементы, которых WCF не ожидает.
Кто-нибудь знает, какие элементы WCF ожидает при данной настройке? Есть ли дополнительная информация, которую я должен предоставить? Заранее спасибо.