Savon gem 显示(未知关键字::消息)

Savon gem shows (unknown keyword: :message)

我正在尝试调整 Ryan Bates 的 railscast http://railscasts.com/episodes/290-soap-with-savon?autoplay=true 以将 Savon 用于 wsdl,但我收到“ArgumentError(未知关键字::消息)”

循序渐进:巴西邮政公司

  1. wsdl: https://apphom.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl
  2. 在 SoapUI 5.5.0 上测试它

新肥皂项目

  1. 初始 wsdl:https://apphom.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl

  2. 服务:咨询cep

  3. 点击请求 1 后,我得到

    soapenv:Header/ soapenv:Body cli:consultaCEP ?

  4. “cep”表示“邮政编码”,替换“?”对于“81531980”(有效的邮政编码),并提交请求,我得到以下信息:

    soap:Body 美洲花园 81531980 库里蒂巴 Avenida Coronel Francisco Heráclito dos Santos 100 公关

下一步是对萨翁做同样的事情。所以,我创建了一个新的 rails 应用程序,捆绑 savon gem 并输入控制台:

> rails c
2.7.0 :001 > client = Savon.client(wsdl: "https://apphom.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl")
2.7.0 :002 > client.operations
... :consulta_cep ...
2.7.0 :003 > response = client.call(:consulta_cep, message: { cep: '81531980'} )
Traceback (most recent call last):
        1: from (irb):10
Savon::SOAPFault ((soap:Server) The given SOAPAction consultaCEP does not match an operation.)
2.7.0 :004 > response = client.call(:cli, :consulta_cep, message: { cep: '81531980'} )
Traceback (most recent call last):
        2: from (irb):10
        1: from (irb):11:in `rescue in irb_binding'
ArgumentError (unknown keyword: :message)

我做错了什么?

您需要禁用 SOAPAction HTTP header。为此,添加 soap_action: false.

client = Savon.client(
  wsdl: "https://apphom.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl"
)

response = client.call(:consulta_cep, soap_action: false, message: { cep: '81531980' })

response.body[:consulta_cep_response][:return][:bairro] #=> "Jardim das Américas"