View Single Post
  #8 (permalink)  
Old 02-17-2006, 03:15 AM
bhwang bhwang is offline
Zimbra Employee
 
Posts: 6
Default

Here is one way to do this.

Code:
require 'soap/rpc/driver'  

 
class A < SOAP::SOAPRawString 
  attr :extraattr, true      
  def initialize(name, value)
    super(value)
    @extraattr = {"n" => name}
  end
end

class CreateAccountRequest
   @@schema_element = [["name", "SOAP::SOAPString"], ["password", "SOAP::SOAPString"], ["a", "A[]"]]
  
  attr_accessor :name
  attr_accessor :password
  attr_accessor :a 
 
  
  def initialize(name = nil, password = nil, a = [])
    @name = name
    @password = password
    @a = a  
  end  
end


s = SOAP::RPC::Driver.new('https://zimbra:7071/service/admin/soap/', 
'urn:zimbraAdmin') 
s.options["protocol.http.ssl_config.verify_mode"] = nil 
mNS = 'urn:zimbraAdmin'
s.add_document_method('CreateAccountRequest', 'CreateAccountRequest', 
   [XSD::QName.new(mNS, 'CreateAccountRequest')], 
   [XSD::QName.new(mNS, 'CreateAccoutnResponse')])
s.wiredump_dev = $stdout

puts YAML.dump(s.CreateAccountRequest(
    CreateAccountRequest.new('a','b',[A.new('23','4'), A.new('45','4')])
This will produce soap request

Code:
<?xml version="1.0" encoding="us-ascii" ?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <env:Body>
    <CreateAccountRequest xmlns="urn:zimbraAdmin">
      <name>a</name>
      <a n="23">4</a>
      <a n="45">4</a>
      <password>b</password>
    </CreateAccountRequest>
  </env:Body>
</env:Envelope>

Last edited by bhwang : 02-17-2006 at 03:12 PM.
Reply With Quote