开发者

Consuming Web Services in Ruby that use reserved words as field names

开发者 https://www.devze.com 2023-01-21 20:35 出处:网络
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

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 wo开发者_JAVA技巧rd 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">
  <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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消