这是服务的样子(来自Soap UI):
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-044848C648B0DCCFBC14248931953381">
<wsse:Username>26613</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">h3hzoxJgSNIrNsJTc8gGwdNGhe0=</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">JvR9+Aefno3PVz++ik/47w==</wsse:Nonce>
<wsu:Created>2015-02-25T19:39:55.336Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
这是savon的产物:
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-1">
<wsse:Username>26613</wsse:Username>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">NmU4NWNiYWIxM2M0ZmYyN2IxZjJiNGQ0MGZmZDJkNjJiODJmNmM5OQ==</wsse:Nonce>
<wsu:Created>2015-02-25T16:55:40Z</wsu:Created>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">lr8M7oMCjEsh7Maj07AyW4CoTlE=</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
我注意到的一件事是不同的是mustUnderstand行。我试图像这样添加:
client = Savon.client(
wsdl: 'gofish?wsdl',
pretty_print_xml: true,
log: true,
log_level: :debug,
env_namespace: :soapenv,
soap_header: {'wsse:Security' => 'mustUnderstand="1"'}
)
但这会产生以下结果:
<wsse:Security>mustUnderstand="1"</wsse:Security>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
这不正是我想要的。关于如何进入像SoapUI这样的wsse:Security元素的任何想法都有吗?
修改
根据Steffen的建议,我得到以下结果:
<soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cmn="http://www.sircon.com/WebServices/services/OnboardingServices.wsdl" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" soapenv:mustUnderstand="1">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-1">
<wsse:Username>26613</wsse:Username>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">NTcyN2QyNjliYmMxZjg2Yjc2YjA0MTY0NjE5MjdjZjQ4ZGY0YzlhYQ==
</wsse:Nonce>
<wsu:Created>2015-02-25T21:28:53Z</wsu:Created>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">h8Qfcn6gA4swa/l+LmJR+RdCSto=</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<cmn:RecruiterOnboardingRequest>
<some>key</some>
<and>another one</and>
</cmn:RecruiterOnboardingRequest>
</soapenv:Body>
</soapenv:Envelope>
编辑2:
在此处围绕此问题打开了一张票:https://github.com/savonrb/savon/issues/667。请随时查看以了解更多信息。
答案 0 :(得分:1)
我认为您需要在客户端中定义名称空间,例如
client = Savon.client(
wsdl: 'gofish?wsdl',
pretty_print_xml: true,
log: true,
log_level: :debug,
env_namespace: :soapenv,
namespaces: {'soapenv:mustUnderstand' => "1"}
)
您可能还需要列出所需的所有其他命名空间。
你会尝试一些疯狂的事情。转到gem目录并找到该文件 ... akami-1.2.2 / LIB / akami / wsse.rb
从
更改第158行:attributes! => { "wsse:Security" => { "xmlns:wsse" => WSE_NAMESPACE } }
到
:attributes! => { "wsse:Security" =>
{ "mustUnderstand" => "1",
"xmlns:wsse" => WSE_NAMESPACE} }
这不是很漂亮,但可能有效