4

I am new to Savon2

and passing wsdl url to the Savon.Client, and getting proper response in header, but I am not getting how to pass multiple namespace to the body:

Savon.client(wsdl: 'https://someUrl.com/abcd?wsdl', ssl_verify_mode: :none, pretty_print_xml: true, log: true, env_namespace: :soapenv, namespace_identifier: nil) do
   wsse_auth("api_demo_account", "somePassword", :digest)
end

client.call(:operation_name, message: { 
             "api01Req" => [{"shipCode" => 'ABC', "shipAmount" => 1123,
                             "countryCode" => "USA"}
                           ]}, 
             'attributes' => { "xmlns" => "http://someUrl.com" })

and it is generating code for body like this:

<soapenv:Body>
 <operationName xmlns="http://someUrl.com">
  <xmlns:api01Req>
    <shipCode>ABC</shipCode>
    <shipAmount>1123</shipAmount>
    <countryCode>USA</countryCode>
  </xmlns:api01Req>
 </operationName>
</soapenv:Body>

But I need a request like this:

<soapenv:Body>
 <operationName xmlns="http://someUrl.com">
  <api01Req>
    <ns1:shipCode xmlns:ns1="http://someOtherUrl.com">ABC
    </ns1:shipCode>
    <ns2:shipAmount xmlns:ns2="http://someOtherUrl.com">1123
    </ns2:shipAmount>
    <ns3:countryCode xmlns:ns3="http://someOtherUrl.com">USA
    </ns3:countryCode>
  </api01Req>
 </getTotalPostage>
</soapenv:Body>

like here it is generating ns1, ns2, ns3, etc along with xmlns:ns1, xmlns:ns2, etc.. different URL's, how should I modify the code to get like above request.

jain77
  • 173
  • 1
  • 7
  • did you look into the namespace configuration? http://savonrb.com/version2/globals.html – phoet Mar 28 '18 at 10:50
  • Yeah, after following that documentation I reached to this request. Now, I am not getting how to proceed further. – jain77 Mar 28 '18 at 11:35
  • i don't see you using the `namespaces:` configuration option like its in the documentation namespaces = { "xmlns:v2" => "http://v2.example.com", } Savon.client(namespaces: namespaces) – phoet Mar 28 '18 at 18:53
  • I would need the same thing. How did you manage to do this? – Shimu Jun 25 '18 at 13:27
  • @Shimu: I have generated a hash using ruby code and used [Gyoku](https://github.com/savonrb/gyoku) to generate xml to convert hash to xml request and passed this xml to savon. This helps me to generate the same hash that I need. – jain77 Oct 10 '18 at 12:34

0 Answers0