SOAP Client -getting data from SOAP::Mapping::Object?

Discussion in 'Ruby' started by Mason Brown, May 23, 2007.

  1. Mason Brown

    Mason Brown Guest

    I've been staring at this for too long, and at this point my mind can't
    think clearly enough to continue without help... I've never worked
    with SOAP before, so forgive me if I'm overlooking something simple.

    I'm using Ruby to access data via SOAP from a server (using soap4r and
    http-access2). I know I'm connecting successfully and getting the right
    information, but don't know how to access the data from the response.
    I've been testing with irb using the following:

    require 'soap/wsdlDriver'
    require 'http-access2'
    wsdl = './proton.wsdl'
    driver = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
    driver.options["protocol.http.cookie_store_file"] = './cookie.file'
    driver.login('username', 'password')
    result = driver.getEntities('2588676', 'IPv4Network', '0', '0')
    driver.logout

    The URL for the SOAP server is read correctly from the wsdl file, and
    the methods "login" and "getEntityById" are also read from the wsdl.
    "result" is an array with only one element:
    "result[0].class => SOAP::Mapping::Object"

    The result itself looks like a single string concatenating each of the
    elements received in the response:

    irb(main):013:0> result[0]
    => #<SOAP::Mapping::Object:0xac7e34
    {http://api.proton}value=#<SOAP::Mapping::Object:0xac7cea
    {http://api.proton}id="2588677"
    {http://api.proton}name=#<SOAP::Mapping::Object:0xac78f8>
    {http://api.proton}properties=#<SOAP::Mapping::Object:0xac751a>
    {http://api.proton}type="IPv4Network">>

    According to the WSDL, the response should be type APIEntity.Array,
    which is composed of APIEntity objects with "id", "name", "properties",
    and "type" elements (all defined in the wsdl). So it looks like I'm
    very close to having the data where I can actually use it (as an
    accessible object or even an array), but I'm just not there yet. Can
    anyone tell me how to get the data out of the SOAP::Mapping::Object
    objects?

    Thanks!

    --
    Posted via http://www.ruby-forum.com/.
    Mason Brown, May 23, 2007
    #1
    1. Advertising

  2. Mason Brown

    Guest

    I've only messed with SOAP4r on one project, but I found that I could
    get at the data in the response by treating it like a hash (a nested
    hash, actually).

    If you look at the wsdl for the service you're calling, it should
    define the response you're expecting back... use the element names in
    there as the hash keys. Or, you might be able to find some way of
    iterating through the keys (.each_key maybe) in the response...

    Or maybe I'm totally off base here.... :)

    hth,

    b

    Mason Brown wrote:
    > I've been staring at this for too long, and at this point my mind can't
    > think clearly enough to continue without help... I've never worked
    > with SOAP before, so forgive me if I'm overlooking something simple.
    >
    > I'm using Ruby to access data via SOAP from a server (using soap4r and
    > http-access2). I know I'm connecting successfully and getting the right
    > information, but don't know how to access the data from the response.
    > I've been testing with irb using the following:
    >
    > require 'soap/wsdlDriver'
    > require 'http-access2'
    > wsdl = './proton.wsdl'
    > driver = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
    > driver.options["protocol.http.cookie_store_file"] = './cookie.file'
    > driver.login('username', 'password')
    > result = driver.getEntities('2588676', 'IPv4Network', '0', '0')
    > driver.logout
    >
    > The URL for the SOAP server is read correctly from the wsdl file, and
    > the methods "login" and "getEntityById" are also read from the wsdl.
    > "result" is an array with only one element:
    > "result[0].class => SOAP::Mapping::Object"
    >
    > The result itself looks like a single string concatenating each of the
    > elements received in the response:
    >
    > irb(main):013:0> result[0]
    > => #<SOAP::Mapping::Object:0xac7e34
    > {http://api.proton}value=#<SOAP::Mapping::Object:0xac7cea
    > {http://api.proton}id="2588677"
    > {http://api.proton}name=#<SOAP::Mapping::Object:0xac78f8>
    > {http://api.proton}properties=#<SOAP::Mapping::Object:0xac751a>
    > {http://api.proton}type="IPv4Network">>
    >
    > According to the WSDL, the response should be type APIEntity.Array,
    > which is composed of APIEntity objects with "id", "name", "properties",
    > and "type" elements (all defined in the wsdl). So it looks like I'm
    > very close to having the data where I can actually use it (as an
    > accessible object or even an array), but I'm just not there yet. Can
    > anyone tell me how to get the data out of the SOAP::Mapping::Object
    > objects?
    >
    > Thanks!
    >
    > --
    > Posted via http://www.ruby-forum.com/.
    , May 23, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sham Ramakrishnan
    Replies:
    2
    Views:
    8,332
    Sham Ramakrishnan
    Jul 1, 2003
  2. bashizip
    Replies:
    0
    Views:
    342
    bashizip
    May 19, 2010
  3. Graham

    SOAP 'Mapping error'

    Graham, Nov 25, 2005, in forum: Ruby
    Replies:
    1
    Views:
    91
    NAKAMURA, Hiroshi
    Nov 26, 2005
  4. bradrover
    Replies:
    1
    Views:
    143
    NAKAMURA, Hiroshi
    Jun 16, 2007
  5. Ruby Rookie

    accessing SOAP::Mapping::Object

    Ruby Rookie, Aug 13, 2007, in forum: Ruby
    Replies:
    2
    Views:
    239
    Ruby Rookie
    Aug 14, 2007
Loading...

Share This Page