tags:

views:

36

answers:

1

I'm attempting to consume a WebService where one of the complex types in the WSDL has a field name that uses a Ruby reserved word. When I call a method returning one of these complex types and attempt to access the data, I get an error.

How can I consume this web service that uses a reserved word in Ruby?

The relevant section of the WSDL is:

<s:complexType name="someObject">
  <s:sequence>
    <s:element minOccurs="0" name="field1" type="s:string"/>
    <s:element minOccurs="0" name="field2" type="s:boolean"/>
    <s:element minOccurs="0" name="field3" type="s:string"/>
    <s:element minOccurs="0" name="class" type="s:string"/> 
    <s:element minOccurs="0" name="field4" type="s:string"/>
  </s:sequence>
  <s:attribute form="unqualified" name="type" type="s:string"/>
</s:complexType>

Here is the XML coming back from my method call:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  <soap:Body>
    <MethodCallResponse>
      <MethodCallResult>
        <results>
          <object type="someObject">
            <field1>Whatever</field1>
            <field2>true</field2>
            <field3>TCP</field3>
            <class>CLIENT</class>
          </object>
        </results>
      </MethodCallResult>
    </MethodCallResponse>
  </soap:Body>
</soap:Envelope>

The error:

undefined method `class_eval' for "CLIENT":String

I am using ruby 1.8.7-p302.

A: 

You're probably looking for something like the BlankState method. The idea is that you create an encapsulating class for your data that undefines some the methods that are colliding with the poorly named types.

pbaumann