【问题标题】:Savon soap request ruby formatSavon soap 请求红宝石格式
【发布时间】:2013-08-21 02:43:15
【问题描述】:

我目前正在从事新项目,我对 savon 非常陌生。 我目前正在使用 ruby​​-1.8.7 和 savon-1.0.0,并且我有以下 SOAP XML 请求

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservices">
<soapenv:Header/>
<soapenv:Body>
<web:InvokeComponent1 soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<PartnerName xsi:type="xsd:string">ABC</PartnerName>
<ComponentName xsi:type="xsd:string">TestingServices</ComponentName>
<arg1Value xsi:type="xsd:string">[CONTROL]
RequestID=83f6baab
RequestTime=13:14:15
RequestDate=08/08/2013
GenerateLead=N
Auto=Y
</arg1Value>
<RaUID xsi:type="xsd:string">username</RaUID>
<RaPW xsi:type="xsd:string">password1</RaPW>
<AgNO xsi:type="xsd:string">12345</AgNO>
</web:InvokeComponent1>
</soapenv:Body>
</soapenv:Envelope>

这是我为此请求自动化编写的 Savon 代码,显然下面提到的代码不起作用,因为我需要一些输入。

  1. 我不确定在哪里包含soapenv:Header,我尝试将请求放入如下代码所示(当前已注释),但我得到'undefined method `header=' for # (NoMethodError)'。在 savon 请求中包含标头在哪里?

  2. 在 SOAP 请求名称中,我有一个附加属性 soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 我应该在哪里包含这个附加属性。

    client = Savon::Client.new do |wsdl|
    wsdl.document = "https://www.abc.com/webservices/RemotePublicGateway.cfc?wsdl"  # this is not actual WSDL
    end
    
    testing_string = '[CONTROL]
    RequestID=83f6baab
    RequestTime=13:14:15
    RequestDate=08/08/2013
    GenerateLead=N
    Auto=Y'
    
     response = client.request :web, "InvokeComponent1" do
    #client.header = { }
     soap.body = {
    :PartnerName  => 'ABC', :attributes! => { :PartnerName => { 'xsi:type' => "xsd:string" } },
    :ComponentName => 'TestingServices', :attributes! => { :ComponentName => { 'xsi:type' => "xsd:string" } },
    :arg1Value => testing_string, :attributes! => { :arg1Value => { 'xsi:type' => "xsd:string" } },
    :RaUID => 'username', :attributes! => { :RaUID => { 'xsi:type' => "xsd:string" } },
    :RaPW => 'password1', :attributes! => { :RaPW => { 'xsi:type' => "xsd:string" } },
    :AgNO=> '12345', :attributes! => { :AgNO => { 'xsi:type' => "xsd:string" } }
    }
    end
    

【问题讨论】:

  • savon 1.0.0 已弃用。你为什么用它?为什么要在新项目中使用 ruby​​ 1.8.7?
  • 好的,让我试试新版本的 Savon,这个项目是已经存在的更大项目的一部分,它正在使用 1.8.7,我不能只为这个项目切换到新版本。

标签: ruby soap savon


【解决方案1】:

在“soap.body”值之后添加以下行,它也适用于 SAVON 1.0.0 和 Ruby 1.8.7

:AgNO=> 'XXXXXXXXX...}},
:order!     => [:PartnerName, :ComponentName,:arg1Value,:RaUID,:RaPW,:AgNO]
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-20
    • 2013-01-22
    • 1970-01-01
    • 1970-01-01
    • 2019-12-17
    • 2019-08-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多