问题描述
我正在尝试使用 Savon gem 连接到 Web 服务.我对服务的了解:
I'm attempting to connect to a web service using Savon gem. What I know about service:
- wsdl 文件网址.../service.svc?wsdl"
- 登录登录"
- 密码密码"
- 域域"
我通过 SoapUI 成功连接到服务.我在 GUI 中输入 wsdl url、登录名、密码和域,文档看起来像:
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>
现在我正在尝试通过 Savon 连接:
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})
产生此错误的原因:
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>'
当我不使用域时:
...
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>'
推荐答案
wasabi gem from dependencies 似乎在没有 httpclient gem 的情况下有问题.如果 savon 的版本是 2.3.3,请安装 gem httpclient.. 它不在依赖项中,但应该是.
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.
这篇关于Ruby Savon 身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!