How to use objects with xsi:types in Savon

岁酱吖の 提交于 2019-12-19 02:55:50

问题


I'm trying to use Savon to make some SOAP requests, but I'm afraid I need to go beyond the basics somewhat.

I need to send something along the lines of:

<env:Body>
  <wsdl:methodName>
    <parameter xsi:type='ValueClass'>value</parameter>
  </wsdl:methodName>
</env:Body>

Now, if I didn't have to specify that xsi:type, it would be a simple matter of:

client.method_name { |soap| soap.body = {:parameter => 'value'} }

The problem is the xsi:type in the parameter; due to the way the web service I'm using is built around polymorphism, I need to explicitly specify what type the parameter is. Is there any way I can do this (preferably without having to generate my own XML?) I'd really love to drop soap4r for good :)

Thanks!


回答1:


Specifying XML attributes in a Hash is pretty ugly, but it's possible:

client.method_name do |soap|
  soap.body = {
    :parameter => 'value',
    :attributes! => { :parameter => { 'xsi:type' => ValueClass } }
  }
end

Please have a look at: http://github.com/rubiii/savon/wiki/SOAP

Until Savon supports XML Schema Attributes, I would suggest you to use Builder
(which comes with Savon) to generate your XML:

client.method_name do |soap|
  xml = Builder::XmlMarkup.new
  soap.body = xml.parameter "value", "xsi:type" => "ValueClass"
end


来源:https://stackoverflow.com/questions/3751682/how-to-use-objects-with-xsitypes-in-savon

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!