我试图制作一个非常简单的SOAP
请求,一个可以在SoapUI
中运行的请求,但是当我执行 Ruby 代码时,我得到了一个' raise_soap_and_http_errors!'异常执行请求。
以下代码 - wsdl_path 中引用的文档在 SOAPUI 中工作,以发出身份验证请求。
require 'savon'
wsdl_path = 'XXXX_soap_interface.wsdl'
client = Savon.client(
:wsdl => wsdl_path,
:ssl_verify_mode => :none,
:raise_errors => true, # false if you don't want to see exceptions
pretty_print_xml: true)
response = client.call(
:authenticate,
message: {:partnerName => 'XXXX', :userName => 'xxxxxx', :password => 'xxxxx'}
)
puts response
我得到的错误是:
savon/response.rb:85:in `raise_soap_and_http_errors!': (SOAP-
ENV:Server) Exception executing request (Savon::SOAPFault)
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/savon-2.4.0/lib/savon/response.rb:14:in `initialize'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/savon-2.4.0/lib/savon/operation.rb:64:in `new'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/savon-2.4.0/lib/savon/operation.rb:64:in `create_response'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/savon-2.4.0/lib/savon/operation.rb:55:in `call'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/savon-2.4.0/lib/savon/client.rb:36:in `call'
from xxx_soap.rb:15:in `<main>'
我正在运行Ruby 1.9,任何人都对如何使这项工作有任何想法?
编辑:用于创建Savon客户端的wsdl_path变量有效。我能够创建客户端并执行client.operations并成功从SOAP服务中恢复操作。只有请求失败。
编辑:从下面添加有用的日志代码后,我收到了回复:
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:common="urn:xxx-com:cloud:common"
xmlns:finsvc="urn:xxx-com:cloud:finsvc"
xmlns:finsvc-13-6-0="urn:xxx-com:cloud:finsvc:13.6.0">
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring>Exception executing request</faultstring>
<detail>
<operationResult>
<errorCode>101</errorCode>
<errorMessage>SOAP error 44 (SOAP 1.1 fault: SOAP-ENV:Client [no subcode] "Validation constraint violation: occurrence v
iolation in element 'userName'" Detail: [no detail] )</errorMessage>
</operationResult>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
无论我将参数放入什么顺序或者是否使用camelcase,消息中指定的第一个参数都会引发上述错误。
答案 0 :(得分:2)
使用
开启日志记录client = Savon.client(
...
log: true,
loglevel: :debug,
pretty_print_xml: true)
如果找不到问题,请分享输出。
如果问题仍然存在,那么你应该采用标准方式:
答案 1 :(得分:1)
所以这一切都证明是wsdl文档中的问题,其中所要求的字段没有这样说,但是服务的响应没有透露这一点。
答案 2 :(得分:0)
wsdl_path
应为完整网址,例如http://domain.name/.../soap.wsdl
。