Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request doesn't pass parameters in the right order #592

Open
afn opened this issue Jun 30, 2014 · 18 comments
Open

Request doesn't pass parameters in the right order #592

afn opened this issue Jun 30, 2014 · 18 comments

Comments

@afn
Copy link

afn commented Jun 30, 2014

I'm calling a SOAP service with Savon 2.5.1 like this:

client.call(:operation_name, message: { 'request' => some_hash })

The generated request contains the keys and values from some_hash in the order in which they appear in the hash, rather than the order specified by the WSDL schema. Therefore, depending on the ordering of the hash, the request may or may not be valid.

Savon should refuse to send non-schema-conforming requests. At a minimum, it should raise an error in such a case, but it would be even better if it could reorder the elements based on the order specified in the schema.

@tjarratt
Copy link
Contributor

tjarratt commented Jul 1, 2014

Thanks for opening this issue @afn -- I wasn't aware of this issue. Based on my understanding of how Savon constructs xml from the given hash, this seems a tad difficult to solve. Savon uses Gyoku which does support ordering.

It seems to solve this, Savon would need to understand the correct order from the schema and provide that order to Gyoku.

I couldn't find any great examples of this online -- it seems that the order should be specified via the parameterOrder attribute on parameters inside of an operation? Does that sound correct?

@afn
Copy link
Author

afn commented Jul 2, 2014

@tjarratt I'm not familiar with parameterOrder, but I think that's unrelated. In our case, the problem is that the XML schema has a <sequence> (which implies an ordering) but Savon is ignoring that order. Here's an example:

client = Savon.client(wsdl: 'http://www.webservicex.net/CurrencyConvertor.asmx?WSDL', log_level: :debug, log: true)
client.call(:conversion_rate, message: {'ToCurrency' => 'USD', 'FromCurrency' => 'CAD'})
# => <?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://www.webserviceX.NET/" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><tns:ConversionRate><tns:ToCurrency>USD</tns:ToCurrency><tns:FromCurrency>CAD</tns:FromCurrency></tns:ConversionRate></env:Body></env:Envelope>

Note how the request has <ToCurrency> before <FromCurrency> even though the WSDL file has:

<s:element name="ConversionRate">
  <s:complexType>
    <s:sequence>
      <s:element minOccurs="1" maxOccurs="1" name="FromCurrency" type="tns:Currency"/>
      <s:element minOccurs="1" maxOccurs="1" name="ToCurrency" type="tns:Currency"/>
    </s:sequence>
  </s:complexType>
</s:element>

This request technically violates the schema, although this particular server is forgiving of the error and works anyway. Unfortunately, not all servers are as forgiving; one of the web services we've integrated with actually silently ignores elements that are out of order.

Thanks again!
Tony

@tjarratt
Copy link
Contributor

tjarratt commented Jul 3, 2014

It seems rather straightforward to support the tag. Thanks for helping me understand this better.

Sent From A Very Small Keyboard

On Jul 2, 2014, at 10:29, Tony Novak [email protected] wrote:

@tjarratt I'm not familiar with parameterOrder, but I think that's unrelated. In our case, the problem is that the XML schema has a (which implies an ordering) but Savon is ignoring that order. Here's an example:

client = Savon.client(wsdl: 'http://www.webservicex.net/CurrencyConvertor.asmx?WSDL', log_level: :debug, log: true)
client.call(:conversion_rate, message: {'ToCurrency' => 'USD', 'FromCurrency' => 'CAD'})

=> <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://www.webserviceX.NET/" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">env:Bodytns:ConversionRatetns:ToCurrencyUSD/tns:ToCurrencytns:FromCurrencyCAD/tns:FromCurrency/tns:ConversionRate/env:Body/env:Envelope

Note how the request has before even though the WSDL file has:

<s:element name="ConversionRate">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="FromCurrency" type="tns:Currency"/>
<s:element minOccurs="1" maxOccurs="1" name="ToCurrency" type="tns:Currency"/>
/s:sequence
/s:complexType
/s:element
This request technically violates the schema, although this particular server is forgiving of the error and works anyway. Unfortunately, not all servers are as forgiving; one of the web services we've integrated with actually silently ignores elements that are out of order.

Thanks again!
Tony


Reply to this email directly or view it on GitHub.

@codebrane
Copy link

I have the same issue with WS-Security. The web service requires the Timestamp before the UsernameToken but Savon always puts Timestamp last so I get 'action mismatch' error from the server. Is there a way to order the elements in the WS-Security header?

@tjarratt
Copy link
Contributor

@codebrane I'm afraid that there isn't some easy, obvious answer to this. It's necessary to do the hard work in Savon to make this work, and unfortunately I don't have a lot of time to investigate this more. Even if I did, I don't have access to a SOAP server that would allow me to verify that any changes to Savon would work.

I'm more than happy to merge any pull requests for this behavior, or to answer questions any potential contributor might have, but I can't recommend any quick fixes today.

@devwout
Copy link

devwout commented Jul 6, 2015

I encountered the same issue and monkey patched savon so it will always put the (top-level) keys in a SOAP request in the same order they were defined in the WSDL request. This may serve as a quick fix.

# Monkey patch savon to automatically put message keys
# in the order defined in the WSDL.
class Savon::Builder
  alias :message_without_order :message

  def message
    params = @wsdl.operations[@operation_name][:parameters].keys
    message = @locals[:message]
    ordered_message = {}

    params.each do |param_name|
      ordered_message[param_name.to_s] = message[param_name.to_s]
    end

    @locals[:message] = ordered_message

    message_without_order
  end
end

@janraasch
Copy link
Contributor

Hi there, I think we just ran into this issue :)

So I just wanted to check, if this issue is still unresolved?

@tjarratt suggested that a solution using the sequence tag should be straight-forward so I suppose my question is: Has that solution been implemented somewhere?

@tjarratt
Copy link
Contributor

tjarratt commented Mar 4, 2016

@janraasch you'd probably need to look at all of the forks of Savon to see if anyone implemented it. I can't think of any PRs for it, but I'm not sure that I would remember one, even if I had merged it myself.

@tjarratt tjarratt closed this as completed Mar 4, 2016
@tjarratt tjarratt reopened this Mar 4, 2016
@warnickr
Copy link

I just submitted a pull request (#802) that fixes the element sequencing issue and also fixes a namespace issue when dealing with array schema elements.

@warnickr
Copy link

I updated the pull request to play nicer with existing Savon features, and to use Gyoku to correctly order the elements.

In order to activate the automatic ordering based on the XML schema, you need to include an :order! key with a value of :use_schema in the top-level parameter hash

@atz
Copy link

atz commented Feb 7, 2018

I think we duplicated this ticket in #859

@stale
Copy link

stale bot commented Apr 9, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Apr 9, 2018
@warnickr
Copy link

warnickr commented Apr 9, 2018

It would be great to get some kind of solution for this merged into Savon. The pull request that I submitted has fixed the issue for us. Do we want something different?

@stale stale bot removed the wontfix label Apr 9, 2018
@stale
Copy link

stale bot commented Jun 8, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 8, 2018
@stale stale bot closed this as completed Jun 15, 2018
@warnickr
Copy link

I need to update the pull request when I get some time.

@quevon24
Copy link

I'm having the same problem, How can iI fix it to keep the order?

@warnickr
Copy link

The pull request provides a way to keep the ordering, but it needs to be updated.

@pcai
Copy link
Member

pcai commented Oct 1, 2024

reopening with an updated commit off of main branch. can someone verify if this commit addresses their issue?:

7351ccd

@pcai pcai reopened this Oct 1, 2024
@stale stale bot removed the stale label Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

9 participants