der kl@mmeraffe | ruby. java. development.

a developers guide to the world of code

Tuesday, August 15, 2006

Working with wsdl2r, soap4r and complex types

Ruby has great support for SOAP built in. Trivial calls at least. Look at this example:

require 'soap/rpc/driver'
stub ="http://localhost:8080",
stub.add_method('gimmeAString', 'a_string')
p stub.gimmeAString("huhu!")

Easy, isn't it? You just create a new Driver object by handing over the location of the web service and its namespace. After that you can add the method you want to call and invoke it. Thats it. At least at the "Example-Stage". I real life, you need to declare complex types and use basic authentication and stuff. How to do that?
With soap4r, the standard soap framework for ruby, comes a nice script called "wsdl2ruby.rb". Example:
./wsdl2ruby.rb --wsdl coolWSDLFile.wsdl --type client 

That generates the complex types and the whole driver class you need to access your web service. Well, in theory, as brendon wilson describes in his article (thats written a lot better than this one here :-)). Because wsdl2ruby (and the whole wsdl4r part of the soap4r framework) is still in alpha stage, you can't expect too much. In my case, it couldn't handle all the complex types, so i had to fix it manually. Its not too difficult. Once you've got a generated driver you can add all necessary complex types that are missing and use the driver like in the first example at the top of this article.

A complex type definition looks like this (taken from the soap4r documentation):

require 'soap/mapping'

SampleStructServiceNamespace = ''

class SampleStruct; include SOAP::Marshallable
attr_accessor :sampleArray
attr_accessor :date

def initialize
@sampleArray = SampleArray[ "cyclic", self ]
@date =

def wrap( rhs )
@sampleArray = SampleArray[ "wrap", rhs.dup ]
@date =

class SampleArray < Array; include SOAP::Marshallable

To use this struct, just use it as a type in the method-definition:
stub.add_method('anotherMethod', 'sampleStruct')

btw, soap4r comes bundled with lots of extremely helpfull examples for all kind of usages.

As of basic authentication, you need to install http-access2.

With an additional line of code,
<< ["ws_url", "username", "password"]

basic authentication is done. More Information on that at Chris McMahons Blog

The SOAP implementation in Ruby itself is great. It seems to be reliable and it is rubyish to code (i.e "easy"). The wsdl2ruby generator needs some more work (i tried a second wsdl file, but that too didn't work), but it helped me a lot to write a SOAP-driver for my specific web service.

Another nice tutorial is here.

add to | submit to digg | submit to reddit


  • At 5:06 AM, Anonymous Anonymous said…

    I used wsdl2ruby to generate ruby coding out of a wsdl (--type server). Now I have to extend the coding in order to implement the functionalities of the service.
    However, I do not know where to extend the coding. There is a ... script and a ...Servant script. When is which of the both called? How do I get access to the data structure I send and how can I build the data structure? Can someone help me or knows a good website where this is explained?

    Would be very great!
    Thanks in advance!

  • At 8:43 PM, Anonymous Anonymous said…

    Hi Guys,Just registered here and looking to have a great time. I am looking for the best cash gifting program out there in the internet. Can you guide me?

    Below are some sites that I found and I am not sure how much they are going to help me.
    [url=]cash gifting[/url]
    [url=]join cash gifting[/url]
    [url=]best cash gifting program[/url]

  • At 12:35 AM, Anonymous order viagra online said…

    I, of course, a newcomer to this blog, but the author does not agree

  • At 10:22 PM, Anonymous Anonymous said…

    Данный пост — одно из редких исключений, когда читаешь с интересом и что-то для себя выносишь. Спасибо автору. Добавлю в избранное[url=].[/url] :)

  • At 3:27 PM, Anonymous Anonymous said…

    researchers have repeated their measurements with the apparatus moved from its initial distance of 38 m from the reactor's core to 48 m. A comparison of data from the buy viagra australia in the wall region but outside the viscous sub-layer is the distance from the wall y . Some of the features of the coherent structures raise doubts about this conclusion. Viagra cost uk These clothes for sleeping are able to absorb more moisture, meaning that your sweat does not stay on your skin and instead is absorbed

  • At 10:26 AM, Anonymous Anonymous said…

    For this, you will need to be over 18 years of age uk lumigan Moreover, prolonged use of antibiotics gives rise to the generation of resistant bacteria
    I also like the soothing and calming effects of aloe on my skin generic cymbalta A guide describing the symptoms of depression and the different kinds of treatment available
    Whole grains contain fibers that are necessary for many systems of the body to run smoothly Viagra for women price So, in order to avoid these risks in women, our prominent scientists have formulated a very effective product called Gem, which can help to fight against arrays of symptoms that can them badly, during cessation of their menstrual
    Recent research has found that babies that die of cot death have brains that are low in serotonin iressa A mixture of shredded apples and honey is also another one of several home remedy acne treatments that you could use
    A study shows that more of the people who went through acupuncture did not have to take pain relievers No rx Diabecon over the counter Try and avoid stressful situations where it can affect the levels of anxiety in your body

  • At 11:29 PM, Anonymous Anonymous said…

    Women, more than men complain about this lithium side effect, which is usually brought on a couple of years after lithium medication has been started lumigan price So your next workout you would squat with 275 lbs for 6 sets of 5
    As with any supplement or medication finding the right dosage can be a real challenge generic cymbalta There is a need for research on the effectiveness of psychosocial treatments for depression in youth.
    In addition to your aerobic work out, you will need to do some toning exercises to strengthen the muscles and give them that lean and attractive look that looks great in swimwear viagra for women au Read the labels, and buy from a reputable dealer
    If you want an high sex drive and sexual staying power, you need high levels of testosterone which is the male sex hormone, its critical for overall and sexual health and the good news is there are herbs you can take to top it up and the two best ones are Tribulus and Tonkgat Ali buy iressa In some wearers' mind, this is a symbol of richness
    The initial years on my journey were not spent trying to access my inner voice, but to learn the fundamentals of how to live a healthy life, such as how to stick to my food plan while traveling, get enough rest, and fit exercise into a busy schedule Price for Diabecon Uses Children with separation anxiety suffer from a paralyzing fear of leaving the safety of their parents and home

  • At 10:24 AM, Anonymous Anonymous said…

    Wow! Finally I got а web site from where
    I knoω how to in fact obtaіn usеful facts regаrԁing my stuԁy and knowledge.

    Mу blog:

  • At 8:20 AM, Anonymous Anonymous said…

    There are a lot of different was to make name badges: this
    is just one example. Fortunately, there are a variety of skin tag removal treatments you can use.
    Click OK and wait a second or two for the effect to be applied.

    Also visit my web-site; tea tree oil for skin tags ()

  • At 2:52 AM, Anonymous Anonymous said…

    I just like the valuable information you provide in
    your articles. I will bookmark your blog and test once more here
    regularly. I'm rather certain I'll be informed
    lots of new stuff proper right here! Best of luck for the

    Check out my page ... back pain lower right side


Post a Comment

Links to this post:

Create a Link

<< Home