0

我正在尝试使用 Savon 访问具有可用 WSDL 的 SOAP API。

在 WSDL 中,它定义了一个 complexType,如下所示:

<s:complexType name="UserAdd">
  <s:sequence>
    <s:element minOccurs="1" maxOccurs="1" nillable="true" name="user_location" type="s:string"/>
    <s:element minOccurs="1" maxOccurs="1" nillable="true" name="number" type="s:string"/>
    <s:element minOccurs="1" maxOccurs="1" nillable="true" name="user_table" type="s:string"/>
  </s:sequence>
</s:complexType>

我知道服务器期待这种格式的请求:

<item>
  <key xsi:type="xsd:string">user_location</key>
  <value xsi:type="xsd:string">here</value>
</item>
<item>
  <key xsi:type="xsd:string">number</key>
  <value xsi:type="xsd:string">1234549789</value>
</item>
<item>
  <key xsi:type="xsd:string">user_table</key>
  <value xsi:type="xsd:string">there</value>
</item>

但是,当我在 Savon 中生成如下查询时:

hash_of_vars = {user_location: here, number: 1234549789, user_table: there}
response = @@call_client.call(:user_add, message: {data: hash_of_vars})

Savon 会生成如下所示的 XML:

<data><user_location>here</user_location><number>1234549789</number><user_table>there</user_table></data>

运行时从服务器收到的错误是:

Cannot use object of type stdClass as array

有没有办法让 Savon 符合 WSDL 并以服务器期望看到的格式输出请求,而不创建明确定义所有项目/键/值关系的哈希?

4

0 回答 0