Savon返回NoMethodError错误

问题描述 投票:1回答:1

我是Savon的新手,在尝试发送soap请求时,为nil:nilClass(NoMethodError)错误获取configure_headers': undefined method%'我的代码看起来像这样

client = Savon.client do
  wsdl "http://sfds:9080/f/sca/BrokerService/WEBINF/wsdl/client/BrokerService_BrokerService.wsdl"
  soap_version "2"
end

response =  client.call(:get_broker_details, message: { brokerId: 'testbroker' })

通过SoapUI请求看起来像这样

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" 
 xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-
 wssecurity-secext-1.0.xsd" 
 xmlns:xyz="http://xml.bnz.co.nz/bnzintegrationcommon/BNZServiceHeadeV120" 
 xmlns:brok="http://xml.xyz.co.nz/brokerservice/BrokerService">
   <soap:Header>
     <oas:Security>
     <!--Optional:-->
     <oas:UsernameToken>
        <oas:Username></oas:Username>
        <oas:Password></oas:Password>
     </oas:UsernameToken>
  </oas:Security>
     <x:serviceHeaderV120>
     <user>
        <channel>BKLP</channel>
        <!--Optional:-->
        <id idType="staffId">631447</id>
        <!--Optional:-->
        <subId></subId>
        <!--Optional:-->
        <location>BRCH0573</location>
     </user>
     <application>
        <id>1</id>
        <!--Optional:-->
        <correlationToken>11111</correlationToken>
     </application>
  </x:serviceHeaderV120>
</soap:Header>
 <soap:Body>
    <brok:getBrokerDetails>
       <getBrokerDetailsRequest>
         <brokerId>ZS1002</brokerId>
       </getBrokerDetailsRequest>
    </brok:getBrokerDetails>
 </soap:Body>
</soap:Envelope>

将非常感谢任何帮助。

ruby soap savon
1个回答
1
投票

如果你看看section of source code that the stack trace points to,错误的原因很容易解决:

CONTENT_TYPE = {
  1 => "text/xml;charset=%s",
  2 => "application/soap+xml;charset=%s"
}

# ...

# This line was the cause of the error:
@http_request.headers["Content-Type"] ||= CONTENT_TYPE[@globals[:soap_version]] % @globals[:encoding]

该错误源于您在客户端设置soap_version "2"String)的事实。相反,正如你从上面的哈希看到的那样,它需要是一个Integer

client = Savon.client do
  wsdl "http://sfds:9080/f/sca/BrokerService/WEBINF/wsdl/client/BrokerService_BrokerService.wsdl"
  soap_version 2 # <-- !!!
end

这个微妙的事实is documented由图书馆。

© www.soinside.com 2019 - 2024. All rights reserved.