Ruby Savon authentication

放肆的年华 提交于 2019-12-13 14:39:36

问题


I'm attempting to connect to a web service using Savon gem. What I know about service:

  • wsdl file url ".../service.svc?wsdl"
  • login "login"
  • password "password"
  • domain "domain"

I successfully connected to the service via SoapUI. I entered wsdl url, login, password and domain in the GUI and the document looks like:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:irc="(...url...)">
   <soapenv:Header/>
   <soapenv:Body>
      <irc:MyService>
         <irc:request>
            <irc:Id>1</irc:Id>
         </irc:request>
      </irc:MyService>
   </soapenv:Body>
</soapenv:Envelope>

Now I'm trying to connect via Savon:

require "savon"
client = Savon.client(
  wsdl: ".../service.svc?wsdl",
  ntlm: ["login", "password", "domain"]
)
client.call(:my_service, message: {id: 1})

Which produces this error:

D, [2013-09-11T15:57:59.880241 #12078] DEBUG -- : HTTPI GET request to xxx.yyy.zz (net_http)
/home/juraj/.rvm/gems/ruby-2.0.0-p195/gems/wasabi-3.2.0/lib/wasabi/resolver.rb:44:in `load_from_remote': Error: 401 (Wasabi::Resolver::HTTPError)
    from /home/juraj/.rvm/gems/ruby-2.0.0-p195/gems/wasabi-3.2.0/lib/wasabi/resolver.rb:32:in `resolve'
    from /home/juraj/.rvm/gems/ruby-2.0.0-p195/gems/wasabi-3.2.0/lib/wasabi/document.rb:139:in `xml'
    from /home/juraj/.rvm/gems/ruby-2.0.0-p195/gems/wasabi-3.2.0/lib/wasabi/document.rb:157:in `parse'
    from /home/juraj/.rvm/gems/ruby-2.0.0-p195/gems/wasabi-3.2.0/lib/wasabi/document.rb:144:in `parser'
    from /home/juraj/.rvm/gems/ruby-2.0.0-p195/gems/wasabi-3.2.0/lib/wasabi/document.rb:61:in `soap_actions'
    from /home/juraj/.rvm/gems/ruby-2.0.0-p195/gems/savon-2.3.0/lib/savon/operation.rb:21:in `ensure_exists!'
    from /home/juraj/.rvm/gems/ruby-2.0.0-p195/gems/savon-2.3.0/lib/savon/operation.rb:14:in `create'
    from /home/juraj/.rvm/gems/ruby-2.0.0-p195/gems/savon-2.3.0/lib/savon/client.rb:32:in `operation'
    from /home/juraj/.rvm/gems/ruby-2.0.0-p195/gems/savon-2.3.0/lib/savon/client.rb:36:in `call'
    from test.rb:8:in `<main>'

When I don't use domain:

...
ntlm: ["login", "password"]
...

I get different (correct?) error:

D, [2013-09-11T18:58:58.702774 #16226] DEBUG -- : HTTPI GET request to (...url...) (net_http)
I, [2013-09-11T18:58:58.870213 #16226]  INFO -- : SOAP request: (...url...)
I, [2013-09-11T18:58:58.870341 #16226]  INFO -- : SOAPAction: "(...url...)", Content-Type: text/xml;charset=UTF-8, Content-Length: 350
D, [2013-09-11T18:58:58.870436 #16226] DEBUG -- : <?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="(...url...)" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><tns:MyService><id>1</id></tns:MyService></env:Body></env:Envelope>
D, [2013-09-11T18:58:58.870577 #16226] DEBUG -- : HTTPI POST request to (...url...) (net_http)
I, [2013-09-11T18:58:59.173536 #16226]  INFO -- : SOAP response (status 401)
D, [2013-09-11T18:58:59.173642 #16226] DEBUG -- : 
/home/juraj/.rvm/gems/ruby-2.0.0-p195/gems/savon-2.3.0/lib/savon/response.rb:86:in `raise_soap_and_http_errors!': HTTP error (401) (Savon::HTTPError)
    from /home/juraj/.rvm/gems/ruby-2.0.0-p195/gems/savon-2.3.0/lib/savon/response.rb:14:in `initialize'
    from /home/juraj/.rvm/gems/ruby-2.0.0-p195/gems/savon-2.3.0/lib/savon/operation.rb:64:in `new'
    from /home/juraj/.rvm/gems/ruby-2.0.0-p195/gems/savon-2.3.0/lib/savon/operation.rb:64:in `create_response'
    from /home/juraj/.rvm/gems/ruby-2.0.0-p195/gems/savon-2.3.0/lib/savon/operation.rb:55:in `call'
    from /home/juraj/.rvm/gems/ruby-2.0.0-p195/gems/savon-2.3.0/lib/savon/client.rb:36:in `call'
    from test.rb:9:in `<main>'

回答1:


wasabi gem from dependencies seems to have problem without httpclient gem. If the version of savon is 2.3.3, install gem httpclient.. its not in dependencies, but it probably should be.



来源:https://stackoverflow.com/questions/18743570/ruby-savon-authentication

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!