Ruby - SOAP WSDL - Savon Gem. Error with sent request not sending some data

374 views Asked by At

I'm using the Savon gem with Ruby to post requests to a wsdl webservice. The problem is that, when i send the request, the response shows me that the response is OK, but it's lacking one item I send in the request, with the help of the development team, i can see that the webservice gets the request without the item, so i can think that I'm doing something wrong with the request format or data, Because i'm using Savon 2 stable I can't see the request xml Savon send directly.

The item is the last one, the "promotion_rules" one.

    @result = @client.call(
        :create_template, message: {
            :item => [{
                'promotion_id'          => 1,
                'initial_quantity'      => 0,
                :products => [{
                    :product => {
                        'id'                    => 3,
                        'quantity'              => 1
                    }
                }],
                :lists => [{
                    :list => [
                        0,
                        1,
                        2
                    ]
                }],
                :promotion_rules => [{
                    :promotion_rule => {
                        'code'      => "NEW_USER",
                        'value'     => 1
                    }
                }]
            }]
        }
    )

The response i get is:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ws.test.enterprise.com">
  <SOAP-ENV:Body>
    <ns1:createTemplateResponse>
      <item>
        <response>
          <code>000</code>
          <description>Aprobada</description>
          <ticket>99999999</ticket>
        </response>
        <attention>
          <begin>2016-12-23 10:49:50</begin>
          <end>2016-12-23 10:49:50</end>
          <time>0.2</time>
        </attention>
        <template_id>901</template_id>
      </item>
    </ns1:createTemplateResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

The specific data that is required in that items is the following:

<xsd:element name="promotion_rules" maxOccurs="1" minOccurs="0">
  <xsd:complexType>
    <xsd:sequence>
      <xsd:element name="promotion_rule" maxOccurs="unbounded">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="code" type="xsd:string"/>
            <xsd:element name="value" type="xsd:integer"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    </xsd:sequence>
  </xsd:complexType>
</xsd:element>

Thank you in advance.

2

There are 2 answers

0
Lea2501 On

The problem was found in the way the arrays and element where specified, instead of :element it should be 'element':

                'promotion_rules' => [{
                    'promotion_rule' => {
                        'code'       => "NEW_USER_RULE",
                        'value'      => 1
                    }
                }]

Instead of:

                :promotion_rules => [{
                    :promotion_rule => {
                        'code'      => "NEW_USER_RULE",
                        'value'     => 1
                    }
                }]
1
André Meier On

It is not really possible to check the correctness of your payload without the wsdl-file or at least the complete type-definitions (e.g. Item) from the wsdl-file.

According to you debug-output problem: Have you checked savon's debug output? Savon can print your request and response xml payloads to the console using following configuration:

Rails.logger = Logger.new(STDOUT)
Rails.logger.level = LOGGER::DEBUG

then your savon config should include

savon_config = {
  ...
  log: true,
  logger: Rails.logger,
  ...
}

Maybe this'll help you to debug your request-payload?