如何使用Rails 4在savon 2.7中传递Security头

时间:2014-12-17 07:20:21

标签: ruby-on-rails ruby savon

我的标题是

<SOAP-ENV:Header xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Security SOAP-ENV:mustUnderstand="1">
<wsse:UsernameToken>
<wsse:Username>123</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">1234</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header> 

这是我的信息:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:dictionary:com.test.webservices">
<soapenv:Body>
<urn:getPIN/>
</soapenv:Body>
</soapenv:Envelope>

我的代码

soap_header = {
        "wsse:Security" => {
            "@soapenv:mustUnderstand" => 1,
            "wsse:UsernameToken" =>{
                "Username"  => "123",
                "Password"  => "1234",
               "digest" => false
            }
        }
    }

client = Savon.client(wsdl: @wsdl, log: true,:ssl_verify_mode => :none,:soap_header=> soap_header)
response = client.call :getPIN, xml: @message

如何在Savon 2.7中传递标题我们无法访问服务请帮助我们。

2 个答案:

答案 0 :(得分:1)

请尝试这个(在Savon 2文档中找到):

Savon.client(wsse_auth: ["123", "1234"])

答案 1 :(得分:0)

我联系的肥皂终点非常挑剔,我遇到了同样的问题。 (wsse_auth不起作用)

我通过略微修改你的答案解决了这个问题。

  soap_header = {
        "wsse:Security" => {
            "@soapenv:mustUnderstand" => 1,
            "@xmlns:soap" => "http://schemas.xmlsoap.org/wsdl/soap/",
            "@xmlns:wsse" => "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
            "wsse:UsernameToken" =>{
                "wsse:Username"  => "123",
                "wsse:Password"  => "12345",
            }
        }
    }

问题是缺少soapenv:mustUnderstand =“1”