Wsdl - Webservice Client

Discussion in 'Ruby' started by Axel Fuchs, Mar 13, 2010.

  1. Axel Fuchs

    Axel Fuchs Guest

    Hi, I am learning how to use WSDL but none of the Ruby Cookbook book
    samples work any longer. So I created this example:

    #!/usr/bin/ruby

    require 'soap/wsdlDriver'
    wsdl='http://www.abundanttech.com/webservices/deadoralive/deadoralive.wsdl'
    driver=SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver

    XSD::Charset.encoding = 'UTF8'
    result = driver.getTodaysBirthdays(nil)

    The question is: How do I access the elements of result in this example
    and print them out? When I use MAC wsdl client, it look like result is a
    XML structure.

    Thanks!
    --
    Posted via http://www.ruby-forum.com/.
    Axel Fuchs, Mar 13, 2010
    #1
    1. Advertising

  2. Axel Fuchs wrote:
    > Hi, I am learning how to use WSDL but none of the Ruby Cookbook book
    > samples work any longer. So I created this example:
    >
    > #!/usr/bin/ruby
    >
    > require 'soap/wsdlDriver'
    > wsdl='http://www.abundanttech.com/webservices/deadoralive/deadoralive.wsdl'
    > driver=SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
    >
    > XSD::Charset.encoding = 'UTF8'
    > result = driver.getTodaysBirthdays(nil)
    >
    > The question is: How do I access the elements of result in this example
    > and print them out? When I use MAC wsdl client, it look like result is a
    > XML structure.


    I'm afraid I can't answer your question directly, but the soap4r which
    comes bundled with ruby (1.8 at least) is very old. It's better if you
    install the latest soap4r from rubygems:

    sudo gem install soap4r

    then you get a bunch of useful stuff, including wsdl2ruby.rb. Create an
    empty directory, cd into it, then run this:

    wget
    http://www.abundanttech.com/webservices/deadoralive/deadoralive.wsdl
    wsdl2ruby.rb --wsdl deadoralive.wsdl --type client

    This creates a bunch of interface code including sample client,
    DeadOrAliveClient.rb

    Add the following two lines to the top of DeadOrAliveClient.rb (to make
    it use the rubygems version of soap4r, not the old bundled one)

    require 'rubygems'
    gem 'soap4r'

    Then run it using:

    ruby DeadOrAliveClient.rb
    ruby -d DeadOrAliveClient.rb # to get wiredumps

    Note that the DeadOrAliveHttpGet port/binding isn't implemented (and the
    client barfs when it gets to that point). Just use the DeadOrAliveSoap
    interface.

    HTH,

    Brian.
    --
    Posted via http://www.ruby-forum.com/.
    Brian Candler, Mar 15, 2010
    #2
    1. Advertising

  3. Axel Fuchs

    Axel Fuchs Guest

    Brian,
    I really appreciate your help. I tried your steps and they all work. I
    can see all the data in the wire dump. But how can I get to it using one
    of these methods? There must be a way to extract the information.

    Thanks,
    Axel
    --
    Posted via http://www.ruby-forum.com/.
    Axel Fuchs, Mar 15, 2010
    #3
  4. Axel Fuchs wrote:
    > I
    > can see all the data in the wire dump. But how can I get to it using one
    > of these methods? There must be a way to extract the information.


    It's simply the result from the method call, which is an object of class
    GetTodaysBirthdaysResponse.

    Unfortunately, soap4r can't break it down further for you, because the
    stupid WSDL doesn't say any more than that it contains a
    getTodaysBirthdaysResult which is simply a collection of any XML
    elements (note <s:any />)

    <s:element name="getTodaysBirthdaysResponse">
    <s:complexType>
    <s:sequence>
    <s:element minOccurs="0" maxOccurs="1"
    name="getTodaysBirthdaysResult">
    <s:complexType>
    <s:sequence>
    <s:element ref="s:schema" />
    <s:any />
    </s:sequence>
    </s:complexType>
    </s:element>
    </s:sequence>
    </s:complexType>
    </s:element>

    So this is essentially untyped XML. soap4r can't build you an OO
    interface into this; you just have to dig down into the returned XML for
    yourself, like this.

    $ irb --simple-prompt
    >> require 'rubygems'

    => true
    >> gem 'soap4r'

    => true
    >> require 'defaultDriver'

    => true
    >> obj = DeadOrAliveSoap.new

    =>
    #<DeadOrAliveSoap:#<SOAP::RPC::proxy:http://www.abundanttech.com/WebServices/DeadOrAlive/DeadOrAlive.asmx>>
    >> obj.wiredump_dev = STDERR

    => #<IO:0xb7c56f54>
    >> result = obj.getTodaysBirthdays(nil)

    Wire dump:
    ...
    => #<GetTodaysBirthdaysResponse:0xb7620900 @getTodaysBirthdaysResult=...
    >> result.methods - methods

    => ["getTodaysBirthdaysResult", "getTodaysBirthdaysResult="]
    >> br = result.getTodaysBirthdaysResult

    => #<GetTodaysBirthdaysResponse::GetTodaysBirthdaysResult:0xb76207fc
    @schema=...
    @diffgram=...
    >> br.methods - methods

    => ["diffgram", "diffgram=", "__xmlele_any", "set_any", "schema",
    "schema="]
    >> br.diffgram

    => #<SOAP::Mapping::Object:0x..fdbb0aecc
    {}NewDataSet=#<SOAP::Mapping::Object:0x..fdbb0abac
    {}Table=[#<SOAP::Mapping::Object:0x..fdbb0ab34 {}FullName="Cunningham,
    Walter"...
    >> br.diffgram['NewDataSet']

    => #<SOAP::Mapping::Object:0x..fdbb0abac {}Table=[...
    >> br.diffgram['NewDataSet']['Table'][0]

    => #<SOAP::Mapping::Object:0x..fdbb0ab34 {}FullName="Cunningham, Walter"
    {}BirthDate="03/16/1932" {}DeathDate="" {}Age="78"
    {}KnownFor="Astronauts - Other" {}DeadOrAlive="Alive">
    >> br.diffgram['NewDataSet']['Table'][0]['FullName']

    => "Cunningham, Walter"
    >>


    So despite all the complexity of SOAP and WSDL, it doesn't help you at
    all. Why don't you suggest that they change to JSON instead :)

    HTH,

    Brian.
    --
    Posted via http://www.ruby-forum.com/.
    Brian Candler, Mar 16, 2010
    #4
  5. Axel Fuchs

    Axel Fuchs Guest

    Brian,
    thank you very much for your help. This is really unnecessarily complex.
    The only reason I am interested in SOAP is so that I can access the
    patent data information from the European Patent Office (see my other
    post).
    Thanks again,
    Axel
    --
    Posted via http://www.ruby-forum.com/.
    Axel Fuchs, Mar 16, 2010
    #5
  6. Hi All,

    I have created a stand alone webservice tool to access any webservice
    using ruby.
    Just give the url , it will show you all the available method and let u
    access them.
    You need ruby gem Saop4r for it. It uses WSDL2Ruby as the core
    implementation.
    you can download my source code from the attachment to this post or
    below location :-
    http://docs.google.com/uc?id=0By8L7...WJiMWQtNGEzYzdjNDBiMzU0&export=download&hl=en

    The attachment is a .jpg file.Change its extension to .zip and then
    unzip it.

    Read the main.rb file for more instructions....
    Email me at for feedback or any queries.....

    Regards,
    Akshay Jangid

    Attachments:
    http://www.ruby-forum.com/attachment/4872/webservice_in_ruby.zip

    --
    Posted via http://www.ruby-forum.com/.
    Akshay Jangid, Jul 21, 2010
    #6
    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. Dark
    Replies:
    1
    Views:
    4,607
    milfar
    Nov 14, 2008
  2. Chris Bedford
    Replies:
    0
    Views:
    563
    Chris Bedford
    Aug 21, 2003
  3. Stephen Edgecombe

    WSDL.EXE: WSDL Import Directive

    Stephen Edgecombe, Aug 13, 2003, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    226
    Stephen Edgecombe
    Aug 13, 2003
  4. RH
    Replies:
    1
    Views:
    251
    Dino Chiesa [Microsoft]
    May 27, 2004
  5. mrnu

    wsdl.exe fails with WebMethods generated wsdl file

    mrnu, Jun 7, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    198
Loading...

Share This Page